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>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2021-10-12 11:52:22 +02:00 committed by Marge Bot
parent 596597f4a4
commit 50c983402e
1 changed files with 14 additions and 3 deletions

View File

@ -310,8 +310,14 @@ one_time_init(void)
* *
* \sa Used by _mesa_initialize(). * \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 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. * 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, * While holding a global mutex lock, calls several initialization functions,
* and sets the glapi callbacks if the \c MESA_DEBUG environment variable is * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
* defined. * defined.
*
* \sa _math_init().
*/ */
void void
_mesa_initialize(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);
} }