aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/shared.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-02-06 08:19:53 +0100
committermarha <marha@users.sourceforge.net>2012-02-06 08:19:53 +0100
commitada3d2c30b5a7a1a79e128b7326d50c3bab77a8a (patch)
tree30539a1a7c6b011c3a5d8028d7428a1ad2b07546 /mesalib/src/mesa/main/shared.c
parent58ff764d4111bfaa7360c57bc62dd620fbdce06f (diff)
downloadvcxsrv-ada3d2c30b5a7a1a79e128b7326d50c3bab77a8a.tar.gz
vcxsrv-ada3d2c30b5a7a1a79e128b7326d50c3bab77a8a.tar.bz2
vcxsrv-ada3d2c30b5a7a1a79e128b7326d50c3bab77a8a.zip
mesa git update 6 feb 2012
Diffstat (limited to 'mesalib/src/mesa/main/shared.c')
-rw-r--r--mesalib/src/mesa/main/shared.c48
1 files changed, 30 insertions, 18 deletions
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);
}
}