summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/shared.c
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2010-02-01 21:22:10 +0000
committerJosé Fonseca <[email protected]>2010-02-09 11:52:02 +0000
commit1c39dbb90cefad8a5a97e75042466d66ea4270bc (patch)
treea3197ce8a5f6228410fe905c7c989d2198a16d1b /src/mesa/main/shared.c
parentb750786fb149fb1276187bbbd1c042609e5962aa (diff)
mesa: Always do proper ref counting of shared state.
Diffstat (limited to 'src/mesa/main/shared.c')
-rw-r--r--src/mesa/main/shared.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c
index 4d01e8abc6e..6cf63f64210 100644
--- a/src/mesa/main/shared.c
+++ b/src/mesa/main/shared.c
@@ -288,8 +288,8 @@ delete_renderbuffer_cb(GLuint id, void *data, void *userData)
*
* \sa alloc_shared_state().
*/
-void
-_mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
+static void
+free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
{
GLuint i;
@@ -368,3 +368,30 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
_mesa_free(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().
+ */
+void
+_mesa_release_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
+{
+ GLint RefCount;
+
+ _glthread_LOCK_MUTEX(shared->Mutex);
+ RefCount = --shared->RefCount;
+ _glthread_UNLOCK_MUTEX(shared->Mutex);
+
+ assert(RefCount >= 0);
+
+ if (RefCount == 0) {
+ /* free shared state */
+ free_shared_state( ctx, shared );
+ }
+}