virgl: add virgl_context_foreach

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 5 years ago
parent a775fc837e
commit b39a1a901a
  1. 18
      src/virgl_context.c
  2. 9
      src/virgl_context.h

@ -26,6 +26,7 @@
#include <errno.h>
#include "os/os_misc.h"
#include "util/u_hash_table.h"
#include "util/u_pointer.h"
#include "virgl_util.h"
@ -83,3 +84,20 @@ virgl_context_lookup(uint32_t ctx_id)
return util_hash_table_get(virgl_context_table,
uintptr_to_pointer(ctx_id));
}
static enum pipe_error
virgl_context_foreach_func(UNUSED void *key, void *val, void *data)
{
const struct virgl_context_foreach_args *args = data;
struct virgl_context *ctx = val;
return args->callback(ctx, args->data) ? PIPE_OK : PIPE_ERROR;
}
void
virgl_context_foreach(const struct virgl_context_foreach_args *args)
{
util_hash_table_foreach(virgl_context_table,
virgl_context_foreach_func,
(void *)args);
}

@ -25,6 +25,7 @@
#ifndef VIRGL_CONTEXT_H
#define VIRGL_CONTEXT_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -49,6 +50,11 @@ struct virgl_context {
size_t size);
};
struct virgl_context_foreach_args {
bool (*callback)(struct virgl_context *ctx, void *data);
void *data;
};
int
virgl_context_table_init(void);
@ -67,4 +73,7 @@ virgl_context_remove(uint32_t ctx_id);
struct virgl_context *
virgl_context_lookup(uint32_t ctx_id);
void
virgl_context_foreach(const struct virgl_context_foreach_args *args);
#endif /* VIRGL_CONTEXT_H */

Loading…
Cancel
Save