mesa: Always do proper ref counting of shared state.
This commit is contained in:
@@ -835,7 +835,7 @@ _mesa_initialize_context(GLcontext *ctx,
|
|||||||
_glthread_UNLOCK_MUTEX(shared->Mutex);
|
_glthread_UNLOCK_MUTEX(shared->Mutex);
|
||||||
|
|
||||||
if (!init_attrib_groups( ctx )) {
|
if (!init_attrib_groups( ctx )) {
|
||||||
_mesa_free_shared_state(ctx, ctx->Shared);
|
_mesa_release_shared_state(ctx, ctx->Shared);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -843,7 +843,7 @@ _mesa_initialize_context(GLcontext *ctx,
|
|||||||
ctx->Exec = alloc_dispatch_table();
|
ctx->Exec = alloc_dispatch_table();
|
||||||
ctx->Save = alloc_dispatch_table();
|
ctx->Save = alloc_dispatch_table();
|
||||||
if (!ctx->Exec || !ctx->Save) {
|
if (!ctx->Exec || !ctx->Save) {
|
||||||
_mesa_free_shared_state(ctx, ctx->Shared);
|
_mesa_release_shared_state(ctx, ctx->Shared);
|
||||||
if (ctx->Exec)
|
if (ctx->Exec)
|
||||||
_mesa_free(ctx->Exec);
|
_mesa_free(ctx->Exec);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
@@ -933,8 +933,6 @@ _mesa_create_context(const GLvisual *visual,
|
|||||||
void
|
void
|
||||||
_mesa_free_context_data( GLcontext *ctx )
|
_mesa_free_context_data( GLcontext *ctx )
|
||||||
{
|
{
|
||||||
GLint RefCount;
|
|
||||||
|
|
||||||
if (!_mesa_get_current_context()){
|
if (!_mesa_get_current_context()){
|
||||||
/* No current context, but we may need one in order to delete
|
/* No current context, but we may need one in order to delete
|
||||||
* texture objs, etc. So temporarily bind the context now.
|
* texture objs, etc. So temporarily bind the context now.
|
||||||
@@ -988,14 +986,7 @@ _mesa_free_context_data( GLcontext *ctx )
|
|||||||
_mesa_free(ctx->Save);
|
_mesa_free(ctx->Save);
|
||||||
|
|
||||||
/* Shared context state (display lists, textures, etc) */
|
/* Shared context state (display lists, textures, etc) */
|
||||||
_glthread_LOCK_MUTEX(ctx->Shared->Mutex);
|
_mesa_release_shared_state( ctx, ctx->Shared );
|
||||||
RefCount = --ctx->Shared->RefCount;
|
|
||||||
_glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
|
|
||||||
assert(RefCount >= 0);
|
|
||||||
if (RefCount == 0) {
|
|
||||||
/* free shared state */
|
|
||||||
_mesa_free_shared_state( ctx, ctx->Shared );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* needs to be after freeing shared state */
|
/* needs to be after freeing shared state */
|
||||||
_mesa_free_display_list_data(ctx);
|
_mesa_free_display_list_data(ctx);
|
||||||
@@ -1397,7 +1388,6 @@ _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
|
|||||||
{
|
{
|
||||||
if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
|
if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
|
||||||
struct gl_shared_state *oldSharedState = ctx->Shared;
|
struct gl_shared_state *oldSharedState = ctx->Shared;
|
||||||
GLint RefCount;
|
|
||||||
|
|
||||||
ctx->Shared = ctxToShare->Shared;
|
ctx->Shared = ctxToShare->Shared;
|
||||||
|
|
||||||
@@ -1407,13 +1397,7 @@ _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
|
|||||||
|
|
||||||
update_default_objects(ctx);
|
update_default_objects(ctx);
|
||||||
|
|
||||||
_glthread_LOCK_MUTEX(oldSharedState->Mutex);
|
_mesa_release_shared_state(ctx, oldSharedState);
|
||||||
RefCount = --oldSharedState->RefCount;
|
|
||||||
_glthread_UNLOCK_MUTEX(oldSharedState->Mutex);
|
|
||||||
|
|
||||||
if (RefCount == 0) {
|
|
||||||
_mesa_free_shared_state(ctx, oldSharedState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -288,8 +288,8 @@ delete_renderbuffer_cb(GLuint id, void *data, void *userData)
|
|||||||
*
|
*
|
||||||
* \sa alloc_shared_state().
|
* \sa alloc_shared_state().
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
_mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
|
free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
|
||||||
{
|
{
|
||||||
GLuint i;
|
GLuint i;
|
||||||
|
|
||||||
@@ -368,3 +368,30 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared)
|
|||||||
|
|
||||||
_mesa_free(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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -31,7 +31,7 @@ _mesa_alloc_shared_state(GLcontext *ctx);
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared);
|
_mesa_release_shared_state(GLcontext *ctx, struct gl_shared_state *shared);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user