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); }