[Mesa-dev] [PATCH 08/13] mesa: Replace renderbuffer object locks with atomic inc/dec.

Matt Turner mattst88 at gmail.com
Thu Aug 6 17:10:58 PDT 2015


---
 src/mesa/main/fbobject.c     |  1 -
 src/mesa/main/mtypes.h       |  1 -
 src/mesa/main/renderbuffer.c | 15 +++------------
 3 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index cc342c2..918889e 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -90,7 +90,6 @@ void
 _mesa_init_fbobjects(struct gl_context *ctx)
 {
    mtx_init(&DummyFramebuffer.Mutex, mtx_plain);
-   mtx_init(&DummyRenderbuffer.Mutex, mtx_plain);
    mtx_init(&IncompleteFramebuffer.Mutex, mtx_plain);
    DummyFramebuffer.Delete = delete_dummy_framebuffer;
    DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index c597ccc..b8329a0 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3196,7 +3196,6 @@ struct gl_shared_state
  */
 struct gl_renderbuffer
 {
-   mtx_t Mutex; /**< for thread safety */
    GLuint ClassID;        /**< Useful for drivers */
    GLuint Name;
    GLchar *Label;         /**< GL_KHR_debug */
diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index b0d4c8c..53e0b74 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -30,6 +30,7 @@
 #include "formats.h"
 #include "mtypes.h"
 #include "renderbuffer.h"
+#include "util/u_atomic.h"
 
 
 /**
@@ -40,8 +41,6 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
 {
    GET_CURRENT_CONTEXT(ctx);
 
-   mtx_init(&rb->Mutex, mtx_plain);
-
    rb->ClassID = 0;
    rb->Name = name;
    rb->RefCount = 0;
@@ -101,7 +100,6 @@ _mesa_new_renderbuffer(struct gl_context *ctx, GLuint name)
 void
 _mesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
-   mtx_destroy(&rb->Mutex);
    free(rb->Label);
    free(rb);
 }
@@ -168,16 +166,11 @@ _mesa_reference_renderbuffer_(struct gl_renderbuffer **ptr,
 {
    if (*ptr) {
       /* Unreference the old renderbuffer */
-      GLboolean deleteFlag = GL_FALSE;
       struct gl_renderbuffer *oldRb = *ptr;
 
-      mtx_lock(&oldRb->Mutex);
       assert(oldRb->RefCount > 0);
-      oldRb->RefCount--;
-      deleteFlag = (oldRb->RefCount == 0);
-      mtx_unlock(&oldRb->Mutex);
 
-      if (deleteFlag) {
+      if (p_atomic_dec_zero(&oldRb->RefCount)) {
          GET_CURRENT_CONTEXT(ctx);
          oldRb->Delete(ctx, oldRb);
       }
@@ -188,9 +181,7 @@ _mesa_reference_renderbuffer_(struct gl_renderbuffer **ptr,
 
    if (rb) {
       /* reference new renderbuffer */
-      mtx_lock(&rb->Mutex);
-      rb->RefCount++;
-      mtx_unlock(&rb->Mutex);
+      p_atomic_inc(&rb->RefCount);
       *ptr = rb;
    }
 }
-- 
2.3.6



More information about the mesa-dev mailing list