From 86290c81b247d84d34ada743004b33086851161e Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Wed, 24 Aug 2022 04:07:20 +0800 Subject: [PATCH] egl/dri2: Use util_call_once_data to replace usage of mtx_t glFlushMutex Signed-off-by: Yonggang Luo Reviewed-by: Jesse Natalie Part-of: --- src/egl/drivers/dri2/egl_dri2.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index c62e130..be3ae39 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -65,6 +65,7 @@ #include "util/libsync.h" #include "util/os_file.h" #include "util/u_atomic.h" +#include "util/u_call_once.h" #include "util/u_vector.h" #include "mapi/glapi/glapi.h" #include "util/bitscan.h" @@ -133,15 +134,19 @@ dri_set_background_context(void *loaderPrivate) } static void +dri2_gl_flush_get(_glapi_proc *glFlush) +{ + *glFlush = _glapi_get_proc_address("glFlush"); +} + +static void dri2_gl_flush() { static void (*glFlush)(void); - static mtx_t glFlushMutex = _MTX_INITIALIZER_NP; + static util_once_flag once = UTIL_ONCE_FLAG_INIT; - mtx_lock(&glFlushMutex); - if (!glFlush) - glFlush = _glapi_get_proc_address("glFlush"); - mtx_unlock(&glFlushMutex); + util_call_once_data(&once, + (util_call_once_data_func)dri2_gl_flush_get, &glFlush); /* if glFlush is not available things are horribly broken */ if (!glFlush) { -- 2.7.4