From 228fa50acdab3dd6f26b044d9149316a72909f62 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 24 Aug 2020 14:08:06 -0700 Subject: [PATCH] virgl: more robust resource/context table init/cleanup Track whether the tables have been initialized, and avoid double init/cleanup. Signed-off-by: Chia-I Wu Reviewed-by: Gurchetan Singh --- src/virgl_context.c | 5 +---- src/virglrenderer.c | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/virgl_context.c b/src/virgl_context.c index 51991c0..6df2309 100644 --- a/src/virgl_context.c +++ b/src/virgl_context.c @@ -52,10 +52,7 @@ virgl_context_table_init(void) void virgl_context_table_cleanup(void) { - if (virgl_context_table) { - util_hash_table_destroy(virgl_context_table); - virgl_context_table = NULL; - } + util_hash_table_destroy(virgl_context_table); } void diff --git a/src/virglrenderer.c b/src/virglrenderer.c index c9a9772..63245a9 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -47,6 +47,8 @@ struct global_state { void *cookie; const struct virgl_renderer_callbacks *cbs; + bool resource_initialized; + bool context_initialized; bool vrend_initialized; }; @@ -442,8 +444,11 @@ void virgl_renderer_cleanup(UNUSED void *cookie) if (state.vrend_initialized) vrend_renderer_prepare_reset(); - virgl_context_table_cleanup(); - virgl_resource_table_cleanup(); + if (state.context_initialized) + virgl_context_table_cleanup(); + + if (state.resource_initialized) + virgl_resource_table_cleanup(); if (state.vrend_initialized) vrend_renderer_fini(); @@ -476,13 +481,19 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks if (ret) return ret; - ret = virgl_resource_table_init(vrend_renderer_get_pipe_callbacks()); - if (ret) - return ret; + if (!state.resource_initialized) { + ret = virgl_resource_table_init(vrend_renderer_get_pipe_callbacks()); + if (ret) + return ret; + state.resource_initialized = true; + } - ret = virgl_context_table_init(); - if (ret) - return ret; + if (!state.context_initialized) { + ret = virgl_context_table_init(); + if (ret) + return ret; + state.context_initialized = true; + } if (!state.vrend_initialized) { uint32_t renderer_flags = 0; @@ -516,8 +527,11 @@ void virgl_renderer_reset(void) if (state.vrend_initialized) vrend_renderer_prepare_reset(); - virgl_context_table_reset(); - virgl_resource_table_reset(); + if (state.context_initialized) + virgl_context_table_reset(); + + if (state.resource_initialized) + virgl_resource_table_reset(); if (state.vrend_initialized) vrend_renderer_reset();