aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/shared.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
committermarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
commit29b86f9852b2b7ecc31cdfee56679537e40bc6e2 (patch)
tree1e6ec8ccf2dbf773260a1953b8e13c49f9b7c5f5 /mesalib/src/mesa/main/shared.c
parent529236591df7366479a6fac30b387667678fd1ba (diff)
downloadvcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.gz
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.bz2
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.zip
svn merge -r524:HEAD "^/branches/released" .
Diffstat (limited to 'mesalib/src/mesa/main/shared.c')
-rw-r--r--mesalib/src/mesa/main/shared.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/mesalib/src/mesa/main/shared.c b/mesalib/src/mesa/main/shared.c
index 4d01e8abc..e364e2404 100644
--- a/mesalib/src/mesa/main/shared.c
+++ b/mesalib/src/mesa/main/shared.c
@@ -93,12 +93,8 @@ _mesa_alloc_shared_state(GLcontext *ctx)
shared->BufferObjects = _mesa_NewHashTable();
#endif
- /* Allocate the default buffer object and set refcount so high that
- * it never gets deleted.
- * XXX with recent/improved refcounting this may not longer be needed.
- */
+ /* Allocate the default buffer object */
shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0, 0);
- shared->NullBufferObj->RefCount = 1000 * 1000 * 1000;
/* Create default texture objects */
for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
@@ -202,7 +198,7 @@ delete_bufferobj_cb(GLuint id, void *data, void *userData)
ctx->Driver.UnmapBuffer(ctx, 0, bufObj);
bufObj->Pointer = NULL;
}
- ctx->Driver.DeleteBuffer(ctx, bufObj);
+ _mesa_reference_buffer_object(ctx, &bufObj, NULL);
}
@@ -288,8 +284,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;
@@ -335,7 +331,7 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
#endif
#if FEATURE_ARB_vertex_buffer_object
- ctx->Driver.DeleteBuffer(ctx, shared->NullBufferObj);
+ _mesa_reference_buffer_object(ctx, &shared->NullBufferObj, NULL);
#endif
#if FEATURE_ARB_sync
@@ -366,5 +362,32 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
_glthread_DESTROY_MUTEX(shared->Mutex);
_glthread_DESTROY_MUTEX(shared->TexMutex);
- _mesa_free(shared);
+ 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 );
+ }
}