Currently, there is a race condition where if two threads call into OpenGL at the same time, one of them will initialize OpenGL, but the other will barrel on ahead, thinking GL is already initialized, even though the first thread hasn't finished initializing it yet. One of the symptoms of this is that no pixel formats appear to be available, because the first thread hasn't yet enumerated the available pixel formats.
InitOnceExecuteOnce() forces the other thread(s) to wait until initialization is actually done; this resolves the race condition.
Signed-off-by: Chip Davis cdavis@codeweavers.com --- dlls/winemac.drv/opengl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c index b80c8fffb0c..b66af0f1c47 100644 --- a/dlls/winemac.drv/opengl.c +++ b/dlls/winemac.drv/opengl.c @@ -4242,7 +4242,7 @@ static void load_extensions(void) }
-static BOOL init_opengl(void) +static BOOL CALLBACK init_opengl(INIT_ONCE *init_once, void *context, void **param) { static BOOL init_done = FALSE; unsigned int i; @@ -4654,13 +4654,15 @@ static struct opengl_funcs opengl_funcs = */ struct opengl_funcs * CDECL macdrv_wine_get_wgl_driver(PHYSDEV dev, UINT version) { + static INIT_ONCE opengl_init = INIT_ONCE_STATIC_INIT; + if (version != WINE_WGL_DRIVER_VERSION) { ERR("version mismatch, opengl32 wants %u but macdrv has %u\n", version, WINE_WGL_DRIVER_VERSION); return NULL; }
- if (!init_opengl()) return (void *)-1; + if (!InitOnceExecuteOnce(&opengl_init, init_opengl, NULL, NULL)) return (void *)-1;
return &opengl_funcs; }