diff options
author | Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> | 2021-10-12 11:52:22 +0200 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2021-11-04 14:16:55 +0000 |
commit | 50c983402e5e81861a728009feddcc4ec43f8cea (patch) | |
tree | a95a57421a76000dec6de064cf554da1686a6436 /src/mesa | |
parent | 596597f4a446f030945991de689afbc17b6225d8 (diff) |
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@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13364>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/context.c | 17 |
1 files 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); } |