From 50c983402e5e81861a728009feddcc4ec43f8cea Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Tue, 12 Oct 2021 11:52:22 +0200 Subject: [PATCH] mesa/init: replace call_once with manual implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Part-of: --- 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); }