[Mesa-dev] [PATCH 07/13] mesa: Replace program locks with atomic inc/dec.

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


---
 src/mesa/main/mtypes.h     |  1 -
 src/mesa/program/program.c | 15 +++------------
 2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index fcc527f..c597ccc 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2095,7 +2095,6 @@ enum gl_frag_depth_layout
  */
 struct gl_program
 {
-   mtx_t Mutex;
    GLuint Id;
    GLint RefCount;
    GLubyte *String;  /**< Null-terminated program text */
diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
index e94c102..54e3498 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -38,6 +38,7 @@
 #include "prog_parameter.h"
 #include "prog_instruction.h"
 #include "util/ralloc.h"
+#include "util/u_atomic.h"
 
 
 /**
@@ -226,7 +227,6 @@ init_program_struct(struct gl_program *prog, GLenum target, GLuint id)
    assert(prog);
 
    memset(prog, 0, sizeof(*prog));
-   mtx_init(&prog->Mutex, mtx_plain);
    prog->Id = id;
    prog->Target = target;
    prog->RefCount = 1;
@@ -419,7 +419,6 @@ _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog)
       ralloc_free(prog->nir);
    }
 
-   mtx_destroy(&prog->Mutex);
    free(prog);
 }
 
@@ -464,17 +463,11 @@ _mesa_reference_program_(struct gl_context *ctx,
 #endif
 
    if (*ptr) {
-      GLboolean deleteFlag;
       struct gl_program *oldProg = *ptr;
 
-      mtx_lock(&oldProg->Mutex);
       assert(oldProg->RefCount > 0);
-      oldProg->RefCount--;
 
-      deleteFlag = (oldProg->RefCount == 0);
-      mtx_unlock(&oldProg->Mutex);
-
-      if (deleteFlag) {
+      if (p_atomic_dec_zero(&oldProg->RefCount)) {
          assert(ctx);
          ctx->Driver.DeleteProgram(ctx, oldProg);
       }
@@ -484,9 +477,7 @@ _mesa_reference_program_(struct gl_context *ctx,
 
    assert(!*ptr);
    if (prog) {
-      mtx_lock(&prog->Mutex);
-      prog->RefCount++;
-      mtx_unlock(&prog->Mutex);
+      p_atomic_inc(&prog->RefCount);
    }
 
    *ptr = prog;
-- 
2.3.6



More information about the mesa-dev mailing list