Module: Mesa Branch: main Commit: fc5281286dd70cef27c07318e93ef9df8c00014e URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fc5281286dd70cef27c07318e93ef9df8c00014e
Author: Rob Clark <[email protected]> Date: Thu Aug 11 13:02:29 2022 -0700 egl/dri2: Make ref_count atomic In particular, MakeCurrent can be called on multiple threads in parallel. Signed-off-by: Rob Clark <[email protected]> Reviewed-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/dri2/egl_dri2.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 5d4aeec2d95..d0f6d590eee 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -1162,7 +1162,7 @@ dri2_initialize(_EGLDisplay *disp) * to free it up correctly. */ if (dri2_dpy) { - dri2_dpy->ref_count++; + p_atomic_inc(&dri2_dpy->ref_count); return EGL_TRUE; } @@ -1197,7 +1197,7 @@ dri2_initialize(_EGLDisplay *disp) return EGL_FALSE; dri2_dpy = dri2_egl_display(disp); - dri2_dpy->ref_count++; + p_atomic_inc(&dri2_dpy->ref_count); return EGL_TRUE; } @@ -1216,9 +1216,8 @@ dri2_display_release(_EGLDisplay *disp) dri2_dpy = dri2_egl_display(disp); assert(dri2_dpy->ref_count > 0); - dri2_dpy->ref_count--; - if (dri2_dpy->ref_count > 0) + if (!p_atomic_dec_zero(&dri2_dpy->ref_count)) return; _eglCleanupDisplay(disp); @@ -1878,7 +1877,7 @@ dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, * EGLDisplay is terminated and then initialized again while a * context is still bound. See dri2_intitialize() for a more in depth * explanation. */ - dri2_dpy->ref_count++; + p_atomic_inc(&dri2_dpy->ref_count); } }
