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 <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37055>
This commit is contained in:
Rhys Perry 2025-08-28 11:23:31 +01:00 committed by Marge Bot
parent c0e51bcf24
commit 858386da06

View file

@ -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);