From b39a1a901a1e816e2c66917a4d8395c794de1872 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 27 Mar 2020 18:09:13 -0700 Subject: [PATCH] virgl: add virgl_context_foreach Signed-off-by: Chia-I Wu Tested-by: Gurchetan Singh Reviewed-by: Gurchetan Singh --- src/virgl_context.c | 18 ++++++++++++++++++ src/virgl_context.h | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/src/virgl_context.c b/src/virgl_context.c index 86a37f9..51991c0 100644 --- a/src/virgl_context.c +++ b/src/virgl_context.c @@ -26,6 +26,7 @@ #include +#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); +} diff --git a/src/virgl_context.h b/src/virgl_context.h index ab843b6..e6a8ae1 100644 --- a/src/virgl_context.h +++ b/src/virgl_context.h @@ -25,6 +25,7 @@ #ifndef VIRGL_CONTEXT_H #define VIRGL_CONTEXT_H +#include #include #include @@ -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 */