mesa: Use util_call_once_data instead of mtx_t init_once_lock
authorYonggang Luo <luoyonggang@gmail.com>
Tue, 23 Aug 2022 20:00:04 +0000 (04:00 +0800)
committerMarge Bot <emma+marge@anholt.net>
Thu, 20 Oct 2022 01:32:47 +0000 (01:32 +0000)
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19154>

src/mesa/main/context.c

index cbdebb8..b3a32b5 100644 (file)
 #include "util/debug.h"
 #include "util/disk_cache.h"
 #include "util/strtod.h"
+#include "util/u_call_once.h"
 #include "stencil.h"
 #include "shaderimage.h"
 #include "texcompress_s3tc.h"
@@ -239,20 +240,6 @@ one_time_init(const char *extensions_override)
 }
 
 /**
- * One-time initialization flag
- *
- * \sa Used by _mesa_initialize().
- */
-static bool init_done = false;
-static mtx_t init_once_lock;
-static once_flag init_once = ONCE_FLAG_INIT;
-
-static void init_lock(void) {
-   mtx_init(&init_once_lock, mtx_plain);
-}
-
-
-/**
  * Calls all the various one-time-init functions in Mesa.
  *
  * While holding a global mutex lock, calls several initialization functions,
@@ -262,14 +249,9 @@ static void init_lock(void) {
 void
 _mesa_initialize(const char *extensions_override)
 {
-   call_once(&init_once, init_lock);
-
-   mtx_lock(&init_once_lock);
-   if (!init_done) {
-      one_time_init(extensions_override);
-      init_done = true;
-   }
-   mtx_unlock(&init_once_lock);
+   static util_once_flag once = UTIL_ONCE_FLAG_INIT;
+   util_call_once_data(&once,
+      (util_call_once_data_func)one_time_init, extensions_override);
 }