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 09:04:13 +0000 (10:04 +0100)
src/mesa/main/context.c

index 1a290f251adbf7600f8c44ae84436c281575eef4..ddbc631e674e70921d74b08b915a84cc26a2c39c 100644 (file)
@@ -1394,14 +1394,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);
       }