mesa: Replace program locks with atomic inc/dec.
authorMatt Turner <mattst88@gmail.com>
Wed, 5 Apr 2017 00:49:35 +0000 (10:49 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 5 Apr 2017 04:54:49 +0000 (14:54 +1000)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl/standalone.cpp
src/mesa/main/mtypes.h
src/mesa/program/program.c

index 521964bf9cca8337faaecc91c66fd74dcfae503f..52554bb92a27910e123fb9ca2acab531c8cde3ad 100644 (file)
@@ -103,8 +103,6 @@ private:
 void
 init_gl_program(struct gl_program *prog, GLenum target, bool is_arb_asm)
 {
-   mtx_init(&prog->Mutex, mtx_plain);
-
    prog->RefCount = 1;
    prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB;
    prog->is_arb_asm = is_arb_asm;
index 6fb6a514f9fbed0ac7e68e32135e1a206b32a93e..4b23240a4697595365e036653ba53696db263295 100644 (file)
@@ -1939,7 +1939,6 @@ struct gl_program
    /** FIXME: This must be first until we split shader_info from nir_shader */
    struct shader_info info;
 
-   mtx_t Mutex;
    GLuint Id;
    GLint RefCount;
    GLubyte *String;  /**< Null-terminated program text */
index 0e499c655fee79f413c8fcf1e2717e68c6b7f34d..277e6ce2d864d978ab8b346e587d5f718de29761 100644 (file)
@@ -40,6 +40,7 @@
 #include "prog_parameter.h"
 #include "prog_instruction.h"
 #include "util/ralloc.h"
+#include "util/u_atomic.h"
 
 
 /**
@@ -185,7 +186,6 @@ _mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id,
       return NULL;
 
    memset(prog, 0, sizeof(*prog));
-   mtx_init(&prog->Mutex, mtx_plain);
    prog->Id = id;
    prog->Target = target;
    prog->RefCount = 1;
@@ -271,7 +271,6 @@ _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog)
       ralloc_free(prog->nir);
    }
 
-   mtx_destroy(&prog->Mutex);
    ralloc_free(prog);
 }
 
@@ -316,17 +315,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);
          _mesa_reference_shader_program_data(ctx, &oldProg->sh.data, NULL);
          ctx->Driver.DeleteProgram(ctx, oldProg);
@@ -337,9 +330,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;