[Mesa-dev] [PATCH 1/5] mesa/arrayobj: use atomics for reference counting

Bartosz Tomczyk bartosz.tomczyk86 at gmail.com
Mon Apr 10 20:08:52 UTC 2017


---
 src/mesa/main/arrayobj.c | 16 ++++------------
 src/mesa/main/mtypes.h   |  2 --
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index ab1b834b6d..39bdb2e715 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -53,6 +53,7 @@
 #include "varray.h"
 #include "main/dispatch.h"
 #include "util/bitscan.h"
+#include "util/u_atomic.h"
 
 
 /**
@@ -169,7 +170,6 @@ _mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj)
 {
    unbind_array_object_vbos(ctx, obj);
    _mesa_reference_buffer_object(ctx, &obj->IndexBufferObj, NULL);
-   mtx_destroy(&obj->Mutex);
    free(obj->Label);
    free(obj);
 }
@@ -189,16 +189,11 @@ _mesa_reference_vao_(struct gl_context *ctx,
 
    if (*ptr) {
       /* Unreference the old array object */
-      GLboolean deleteFlag = GL_FALSE;
       struct gl_vertex_array_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))
          _mesa_delete_vao(ctx, oldObj);
 
       *ptr = NULL;
@@ -207,18 +202,16 @@ _mesa_reference_vao_(struct gl_context *ctx,
 
    if (vao) {
       /* reference new array object */
-      mtx_lock(&vao->Mutex);
-      if (vao->RefCount == 0) {
+      if (p_atomic_read(&vao->RefCount) == 0) {
          /* this array's being deleted (look just above) */
          /* Not sure this can every really happen.  Warn if it does. */
          _mesa_problem(NULL, "referencing deleted array object");
          *ptr = NULL;
       }
       else {
-         vao->RefCount++;
+         p_atomic_inc(&vao->RefCount);
          *ptr = vao;
       }
-      mtx_unlock(&vao->Mutex);
    }
 }
 
@@ -274,7 +267,6 @@ _mesa_initialize_vao(struct gl_context *ctx,
 
    vao->Name = name;
 
-   mtx_init(&vao->Mutex, mtx_plain);
    vao->RefCount = 1;
 
    /* Init the individual arrays */
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index e5f7cbaa5b..5de464cc1b 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1509,8 +1509,6 @@ struct gl_vertex_array_object
 
    GLchar *Label;       /**< GL_KHR_debug */
 
-   mtx_t Mutex;
-
    /**
     * Does the VAO use ARB semantics or Apple semantics?
     *
-- 
2.12.2



More information about the mesa-dev mailing list