From 1c39dbb90cefad8a5a97e75042466d66ea4270bc Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 1 Feb 2010 21:22:10 +0000 Subject: mesa: Always do proper ref counting of shared state. --- src/mesa/main/shared.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/mesa/main/shared.c') 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 ); + } +} -- cgit v1.2.3