Mesa (main): mesa/init: replace call_once with manual implementation

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Nov 4 14:49:41 UTC 2021


Module: Mesa
Branch: main
Commit: 50c983402e5e81861a728009feddcc4ec43f8cea
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=50c983402e5e81861a728009feddcc4ec43f8cea

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Tue Oct 12 11:52:22 2021 +0200

mesa/init: replace call_once with manual implementation

This will be useful to add parameters to one_time_init().

_MTX_INITIALIZER_NP and Windows don't play nice together,
so I had to keep a call_once() to initialize the mutex.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13364>

---

 src/mesa/main/context.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 51f4c8bc865..ef70090ea99 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -310,8 +310,14 @@ one_time_init(void)
  *
  * \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.
@@ -319,13 +325,18 @@ static once_flag init_once = ONCE_FLAG_INIT;
  * While holding a global mutex lock, calls several initialization functions,
  * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
  * defined.
- *
- * \sa _math_init().
  */
 void
 _mesa_initialize(void)
 {
-   call_once(&init_once, one_time_init);
+   call_once(&init_once, init_lock);
+
+   mtx_lock(&init_once_lock);
+   if (!init_done) {
+      one_time_init();
+      init_done = true;
+   }
+   mtx_unlock(&init_once_lock);
 }
 
 



More information about the mesa-commit mailing list