mesa/main: use call_once instead of open-coding
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 10 Jul 2020 11:08:30 +0000 (13:08 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 14 Jul 2020 10:56:03 +0000 (10:56 +0000)
We already have a utility for this, so let's use that instead.

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5879>

src/mesa/main/context.c

index b8b11b0c450400b4e2feaff4e509810e482c7cab..be2e7df5824e0f75f31ba441083871e66de57445 100644 (file)
@@ -394,11 +394,11 @@ one_time_init(void)
 }
 
 /**
- * One-time initialization mutex lock.
+ * One-time initialization flag
  *
  * \sa Used by _mesa_initialize().
  */
-mtx_t OneTimeLock = _MTX_INITIALIZER_NP;
+static once_flag init_once = ONCE_FLAG_INIT;
 
 
 /**
@@ -413,17 +413,7 @@ mtx_t OneTimeLock = _MTX_INITIALIZER_NP;
 void
 _mesa_initialize(void)
 {
-   static bool initialized;
-
-   mtx_lock(&OneTimeLock);
-
-   /* truly one-time init */
-   if (!initialized)
-      one_time_init();
-
-   initialized = true;
-
-   mtx_unlock(&OneTimeLock);
+   call_once(&init_once, one_time_init);
 }