summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2015-07-30 11:25:27 -0700
committerMatt Turner <[email protected]>2015-09-25 14:08:31 -0700
commit1dd943d7fb5bd374e871436ccf6546327687c761 (patch)
tree8d2fd108be4c6591d847bbde64a2585a2704a0c3
parent3c57a102ebd2efc427a59bf8eb441b4e5dec8553 (diff)
mesa: Add locking to programs.
Reviewed-by: Timothy Arceri <[email protected]> Reviewed-by: Brian Paul <[email protected]>
-rw-r--r--src/mesa/main/mtypes.h1
-rw-r--r--src/mesa/program/program.c19
2 files changed, 12 insertions, 8 deletions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5445d39c560..a872942d2a8 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1888,6 +1888,7 @@ 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 18d6754a99a..e94c1021258 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -226,6 +226,7 @@ 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;
@@ -418,6 +419,7 @@ _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog)
ralloc_free(prog->nir);
}
+ mtx_destroy(&prog->Mutex);
free(prog);
}
@@ -463,17 +465,18 @@ _mesa_reference_program_(struct gl_context *ctx,
if (*ptr) {
GLboolean deleteFlag;
+ struct gl_program *oldProg = *ptr;
- /*mtx_lock(&(*ptr)->Mutex);*/
- assert((*ptr)->RefCount > 0);
- (*ptr)->RefCount--;
+ mtx_lock(&oldProg->Mutex);
+ assert(oldProg->RefCount > 0);
+ oldProg->RefCount--;
- deleteFlag = ((*ptr)->RefCount == 0);
- /*mtx_lock(&(*ptr)->Mutex);*/
+ deleteFlag = (oldProg->RefCount == 0);
+ mtx_unlock(&oldProg->Mutex);
if (deleteFlag) {
assert(ctx);
- ctx->Driver.DeleteProgram(ctx, *ptr);
+ ctx->Driver.DeleteProgram(ctx, oldProg);
}
*ptr = NULL;
@@ -481,9 +484,9 @@ _mesa_reference_program_(struct gl_context *ctx,
assert(!*ptr);
if (prog) {
- /*mtx_lock(&prog->Mutex);*/
+ mtx_lock(&prog->Mutex);
prog->RefCount++;
- /*mtx_unlock(&prog->Mutex);*/
+ mtx_unlock(&prog->Mutex);
}
*ptr = prog;