diff options
author | Chris Robinson <[email protected]> | 2011-08-28 15:44:03 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-08-28 15:44:03 -0700 |
commit | 82244f298ced5fd96dec5ee64c8a5b957b7dfdb4 (patch) | |
tree | b6aa61052cbc1aef2091f41edfc4a6e27034ffbd /Alc | |
parent | 3ab20d4ccbdcaded207cd31ff63c4f9782ba402b (diff) |
Add reference counting to the ALC contexts
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/ALc.c | 58 |
1 files changed, 33 insertions, 25 deletions
@@ -1361,11 +1361,41 @@ static ALvoid InitContext(ALCcontext *pContext) */ static ALCvoid FreeContext(ALCcontext *context) { + LockLists(); + if(context == GlobalContext) + GlobalContext = NULL; + UnlockLists(); + + if(context->SourceMap.size > 0) + { + ERR("FreeContext(%p): deleting %d Source(s)\n", context, context->SourceMap.size); + ReleaseALSources(context); + } + ResetUIntMap(&context->SourceMap); + + if(context->EffectSlotMap.size > 0) + { + ERR("FreeContext(%p): deleting %d AuxiliaryEffectSlot(s)\n", context, context->EffectSlotMap.size); + ReleaseALAuxiliaryEffectSlots(context); + } + ResetUIntMap(&context->EffectSlotMap); + + free(context->ActiveSources); + context->ActiveSources = NULL; + context->MaxActiveSources = 0; + context->ActiveSourceCount = 0; + //Invalidate context memset(context, 0, sizeof(ALCcontext)); free(context); } +static void ALCcontext_Deref(ALCcontext *context) +{ + if(DecrementRef(&context->ref) == 0) + FreeContext(context); +} + /////////////////////////////////////////////////////// @@ -1998,6 +2028,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ALContext = calloc(1, sizeof(ALCcontext)); if(ALContext) { + ALContext->ref = 1; + ALContext->MaxActiveSources = 256; ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) * ALContext->MaxActiveSources); @@ -2059,11 +2091,6 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) *list = (*list)->next; g_ulContextCount--; - if(context == tls_get(LocalContext)) - tls_set(LocalContext, NULL); - if(context == GlobalContext) - GlobalContext = NULL; - Device = context->Device; LockDevice(Device); for(i = 0;i < Device->NumContexts;i++) @@ -2084,26 +2111,7 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) } UnlockLists(); - if(context->SourceMap.size > 0) - { - ERR("alcDestroyContext(): deleting %d Source(s)\n", context->SourceMap.size); - ReleaseALSources(context); - } - ResetUIntMap(&context->SourceMap); - - if(context->EffectSlotMap.size > 0) - { - ERR("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotMap.size); - ReleaseALAuxiliaryEffectSlots(context); - } - ResetUIntMap(&context->EffectSlotMap); - - free(context->ActiveSources); - context->ActiveSources = NULL; - context->MaxActiveSources = 0; - context->ActiveSourceCount = 0; - - FreeContext(context); + ALCcontext_Deref(context); } |