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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user