mesa: Always do proper ref counting of shared state.

This commit is contained in:
José Fonseca
2010-02-01 21:22:10 +00:00
parent b750786fb1
commit 1c39dbb90c
3 changed files with 34 additions and 23 deletions

View File

@@ -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 );
}
}