mesa: Make _mesa_share_state thread safe.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 1 May 2009 17:52:54 +0000 (18:52 +0100)
committerKeith Whitwell <keithw@vmware.com>
Fri, 8 May 2009 13:57:29 +0000 (14:57 +0100)
src/mesa/main/context.c

index d780f91f048b95dbb296aa8f2dddb10ab0296b96..60c48289e4a7cbc9c863e5f91c8a1662cc6c69ca 100644 (file)
@@ -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);
       }