From: José Fonseca Date: Fri, 1 May 2009 17:52:54 +0000 (+0100) Subject: mesa: Make _mesa_share_state thread safe. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d88faf91e9fe222636b33540298ee64bc6f4416c;p=mesa.git mesa: Make _mesa_share_state thread safe. --- 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); }