Module: Mesa Branch: main Commit: a2d6dee4f0e2d4c0face9925fa62e7e701e8625f URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a2d6dee4f0e2d4c0face9925fa62e7e701e8625f
Author: Rob Clark <[email protected]> Date: Thu Aug 11 09:32:29 2022 -0700 egl/wgl: Make ref_count atomic Looks like wgl doesn't have much display state to protect. But it's ref_count should be atomic before we start removing locking from eglapi to protect against MakeCurrent being called in parallel on multiple threads. Signed-off-by: Rob Clark <[email protected]> Acked-by: Eric Engestrom <[email protected]> Reviewed-by: Adam Jackson <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18050> --- src/egl/drivers/wgl/egl_wgl.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/egl/drivers/wgl/egl_wgl.c b/src/egl/drivers/wgl/egl_wgl.c index 7ec1fcf79b7..0d8b627e94b 100644 --- a/src/egl/drivers/wgl/egl_wgl.c +++ b/src/egl/drivers/wgl/egl_wgl.c @@ -318,7 +318,7 @@ wgl_initialize(_EGLDisplay *disp) * to free it up correctly. */ if (wgl_dpy) { - wgl_dpy->ref_count++; + p_atomic_inc(&wgl_dpy->ref_count); return EGL_TRUE; } @@ -338,7 +338,7 @@ wgl_initialize(_EGLDisplay *disp) return EGL_FALSE; wgl_dpy = wgl_egl_display(disp); - wgl_dpy->ref_count++; + p_atomic_inc(&wgl_dpy->ref_count); return EGL_TRUE; } @@ -357,9 +357,7 @@ wgl_display_release(_EGLDisplay *disp) wgl_dpy = wgl_egl_display(disp); assert(wgl_dpy->ref_count > 0); - wgl_dpy->ref_count--; - - if (wgl_dpy->ref_count > 0) + if (!p_atomic_dec_zero(&wgl_dpy->ref_count)) return; _eglCleanupDisplay(disp); @@ -643,7 +641,7 @@ wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, * EGLDisplay is terminated and then initialized again while a * context is still bound. See wgl_intitialize() for a more in depth * explanation. */ - wgl_dpy->ref_count++; + p_atomic_inc(&wgl_dpy->ref_count); } }
