[Mesa-dev] [PATCH 05/13] mesa: Replace buffer object locks with atomic inc/dec.
Matt Turner
mattst88 at gmail.com
Thu Aug 6 17:10:55 PDT 2015
---
src/mesa/main/bufferobj.c | 17 +++--------------
src/mesa/main/mtypes.h | 1 -
2 files changed, 3 insertions(+), 15 deletions(-)
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index cc035ff..78af229 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -47,6 +47,7 @@
#include "texstore.h"
#include "transformfeedback.h"
#include "dispatch.h"
+#include "util/u_atomic.h"
/* Debug flags */
@@ -424,7 +425,6 @@ _mesa_delete_buffer_object(struct gl_context *ctx,
bufObj->RefCount = -1000;
bufObj->Name = ~0;
- mtx_destroy(&bufObj->Mutex);
free(bufObj->Label);
free(bufObj);
}
@@ -443,16 +443,9 @@ _mesa_reference_buffer_object_(struct gl_context *ctx,
{
if (*ptr) {
/* Unreference the old buffer */
- GLboolean deleteFlag = GL_FALSE;
struct gl_buffer_object *oldObj = *ptr;
- mtx_lock(&oldObj->Mutex);
- assert(oldObj->RefCount > 0);
- oldObj->RefCount--;
- deleteFlag = (oldObj->RefCount == 0);
- mtx_unlock(&oldObj->Mutex);
-
- if (deleteFlag) {
+ if (p_atomic_dec_zero(&oldObj->RefCount)) {
assert(ctx->Driver.DeleteBuffer);
ctx->Driver.DeleteBuffer(ctx, oldObj);
}
@@ -463,7 +456,6 @@ _mesa_reference_buffer_object_(struct gl_context *ctx,
if (bufObj) {
/* reference new buffer */
- mtx_lock(&bufObj->Mutex);
if (bufObj->RefCount == 0) {
/* this buffer's being deleted (look just above) */
/* Not sure this can every really happen. Warn if it does. */
@@ -471,10 +463,9 @@ _mesa_reference_buffer_object_(struct gl_context *ctx,
*ptr = NULL;
}
else {
- bufObj->RefCount++;
+ p_atomic_inc(&bufObj->RefCount);
*ptr = bufObj;
}
- mtx_unlock(&bufObj->Mutex);
}
}
@@ -488,7 +479,6 @@ _mesa_initialize_buffer_object(struct gl_context *ctx,
GLuint name)
{
memset(obj, 0, sizeof(struct gl_buffer_object));
- mtx_init(&obj->Mutex, mtx_plain);
obj->RefCount = 1;
obj->Name = name;
obj->Usage = GL_STATIC_DRAW_ARB;
@@ -806,7 +796,6 @@ _mesa_init_buffer_objects( struct gl_context *ctx )
GLuint i;
memset(&DummyBufferObject, 0, sizeof(DummyBufferObject));
- mtx_init(&DummyBufferObject.Mutex, mtx_plain);
DummyBufferObject.RefCount = 1000*1000*1000; /* never delete */
_mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 19f65ee..2adfae2 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1477,7 +1477,6 @@ typedef enum {
*/
struct gl_buffer_object
{
- mtx_t Mutex;
GLint RefCount;
GLuint Name;
GLchar *Label; /**< GL_KHR_debug */
--
2.3.6
More information about the mesa-dev
mailing list