[Mesa-dev] [PATCH 01/13] egl: Use atomic ops on _EGLResource::RefCount
Chad Versace
chad.versace at intel.com
Sat Jul 9 00:00:51 UTC 2016
Mesa was incrementing and decrementing EGL refcounts with ++ and --.
---
src/egl/main/egldisplay.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index bbc3063..78b5d20 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -37,6 +37,8 @@
#include <string.h>
#include "c11/threads.h"
+#include "util/u_atomic.h"
+
#include "eglcontext.h"
#include "eglcurrent.h"
#include "eglsurface.h"
@@ -385,21 +387,20 @@ _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *dpy)
void
_eglGetResource(_EGLResource *res)
{
- assert(res && res->RefCount > 0);
- /* hopefully a resource is always manipulated with its display locked */
- res->RefCount++;
+ assert(res->RefCount > 0);
+ p_atomic_inc(&res->RefCount);
}
/**
* Decrement reference count for the resource.
+ * Return true when the last reference is dropped.
*/
EGLBoolean
_eglPutResource(_EGLResource *res)
{
- assert(res && res->RefCount > 0);
- res->RefCount--;
- return (!res->RefCount);
+ assert(res->RefCount > 0);
+ return p_atomic_dec_return(&res->RefCount) == 0;
}
--
2.9.0.rc2
More information about the mesa-dev
mailing list