diff options
author | Brian Paul <[email protected]> | 2012-01-31 18:23:03 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2012-02-01 07:11:40 -0700 |
commit | 361cd53a77dd48fbf2a0321446c0b7c07365bff9 (patch) | |
tree | 82d1936b9c52b28889a2d4d750269fc3db0b220d /src/mesa/main/shared.c | |
parent | 133c5727b58c60afe6467ecbfe07739c7466d8c8 (diff) |
mesa: use new _mesa_reference_shared_state() function
This cleans up the reference counting of shared context state.
The next patch will use this to fix an actual bug.
NOTE: This is a candidate for the 8.0 branch.
Reviewed-by: José Fonseca <[email protected]>
Diffstat (limited to 'src/mesa/main/shared.c')
-rw-r--r-- | src/mesa/main/shared.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index c3e93b5a583..c07ce823846 100644 --- a/src/mesa/main/shared.c +++ b/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); } } |