From 858386da06009960051f30d2da52c61e30a171e0 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Thu, 28 Aug 2025 11:23:31 +0100 Subject: [PATCH] drm-shim: use atomics for inited This is more thread safe. This is still broken, because another thread could use the global variables after inited is set but before the shim is fully initialized, but I guess it's better than before. Signed-off-by: Rhys Perry Reviewed-by: Samuel Pitoiset Part-of: --- src/drm-shim/drm_shim.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/drm-shim/drm_shim.c b/src/drm-shim/drm_shim.c index f721ace9567..6d090d12292 100644 --- a/src/drm-shim/drm_shim.c +++ b/src/drm-shim/drm_shim.c @@ -204,18 +204,14 @@ destroy_shim(void) static void init_shim(void) { - static bool inited = false; + static uint32_t inited = 0; + drm_shim_debug = debug_get_bool_option("DRM_SHIM_DEBUG", false); /* We can't lock this, because we recurse during initialization. */ - if (inited) + if (p_atomic_cmpxchg(&inited, 0, 1)) return; - /* This comes first (and we're locked), to make sure we don't recurse - * during initialization. - */ - inited = true; - opendir_set = _mesa_set_create(NULL, _mesa_hash_string, _mesa_key_string_equal);