summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/context.c
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2009-05-01 18:52:54 +0100
committerKeith Whitwell <[email protected]>2009-05-08 14:57:29 +0100
commitd88faf91e9fe222636b33540298ee64bc6f4416c (patch)
tree274400bdd1948c9629d2baed2ec1c3fb5530b03e /src/mesa/main/context.c
parent4d28fcfeaa6be438f6739fddcb0661ae97a68919 (diff)
mesa: Make _mesa_share_state thread safe.
Diffstat (limited to 'src/mesa/main/context.c')
-rw-r--r--src/mesa/main/context.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index d780f91f048..60c48289e4a 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1397,14 +1397,21 @@ _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
{
if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
struct gl_shared_state *oldSharedState = ctx->Shared;
+ GLint RefCount;
ctx->Shared = ctxToShare->Shared;
+
+ _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
ctx->Shared->RefCount++;
+ _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
update_default_objects(ctx);
- oldSharedState->RefCount--;
- if (oldSharedState->RefCount == 0) {
+ _glthread_LOCK_MUTEX(oldSharedState->Mutex);
+ RefCount = --oldSharedState->RefCount;
+ _glthread_UNLOCK_MUTEX(oldSharedState->Mutex);
+
+ if (RefCount == 0) {
_mesa_free_shared_state(ctx, oldSharedState);
}