[Mesa-dev] [PATCH 3/5] mesa/renderbuffer: use atomics for reference counting

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


---
 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 d486d01195..f85f26674d 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 8b1577dd3f..d37a60d61c 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3233,7 +3233,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 627bdca66c..ce4f0f229a 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 = 1;
@@ -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);
 }
@@ -195,16 +193,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);
       }
@@ -215,9 +208,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.12.2



More information about the mesa-dev mailing list