From ada3d2c30b5a7a1a79e128b7326d50c3bab77a8a Mon Sep 17 00:00:00 2001 From: marha Date: Mon, 6 Feb 2012 08:19:53 +0100 Subject: mesa git update 6 feb 2012 --- mesalib/src/mesa/main/shared.c | 48 ++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'mesalib/src/mesa/main/shared.c') diff --git a/mesalib/src/mesa/main/shared.c b/mesalib/src/mesa/main/shared.c index c3e93b5a5..c07ce8238 100644 --- a/mesalib/src/mesa/main/shared.c +++ b/mesalib/src/mesa/main/shared.c @@ -388,28 +388,40 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared) /** - * Decrement shared state object reference count and potentially free it - * and all children structures. - * - * \param ctx GL context. - * \param shared shared state pointer. - * - * \sa free_shared_state(). + * gl_shared_state objects are ref counted. + * If ptr's refcount goes to zero, free the shared state. */ void -_mesa_release_shared_state(struct gl_context *ctx, - struct gl_shared_state *shared) +_mesa_reference_shared_state(struct gl_context *ctx, + struct gl_shared_state **ptr, + struct gl_shared_state *state) { - GLint RefCount; - - _glthread_LOCK_MUTEX(shared->Mutex); - RefCount = --shared->RefCount; - _glthread_UNLOCK_MUTEX(shared->Mutex); + if (*ptr == state) + return; + + if (*ptr) { + /* unref old state */ + struct gl_shared_state *old = *ptr; + GLboolean delete; + + _glthread_LOCK_MUTEX(old->Mutex); + assert(old->RefCount >= 1); + old->RefCount--; + delete = (old->RefCount == 0); + _glthread_UNLOCK_MUTEX(old->Mutex); + + if (delete) { + free_shared_state(ctx, old); + } - assert(RefCount >= 0); + *ptr = NULL; + } - if (RefCount == 0) { - /* free shared state */ - free_shared_state( ctx, shared ); + if (state) { + /* reference new state */ + _glthread_LOCK_MUTEX(state->Mutex); + state->RefCount++; + *ptr = state; + _glthread_UNLOCK_MUTEX(state->Mutex); } } -- cgit v1.2.3