summaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-08-29 11:10:17 -0700
committerChris Robinson <[email protected]>2011-08-29 11:10:17 -0700
commitc06f4eb7f7ca6ca698e7be74266eac89c3352a11 (patch)
tree04fe170b5f7578c1c0a7562df18ac0855157b7ac /Alc
parent0abe13e3adfea3e8181bd89064331fe2640c969c (diff)
Hold a reference on the global context
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index e9c6000e..9929ee3b 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1337,11 +1337,6 @@ 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);
@@ -2119,6 +2114,12 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
ALCdevice_StopPlayback(Device);
Device->Flags &= ~DEVICE_RUNNING;
}
+
+ if(GlobalContext == context)
+ {
+ GlobalContext = NULL;
+ ALCcontext_DecRef(context);
+ }
UnlockLists();
ALCcontext_DecRef(context);
@@ -2192,11 +2193,15 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
// context must be a valid Context or NULL
if(context == NULL || IsContext(context))
{
+ ALCcontext *old = GlobalContext;
+ if(context) ALCcontext_IncRef(context);
GlobalContext = context;
- if((context=pthread_getspecific(LocalContext)) != NULL)
+ if(old) ALCcontext_DecRef(old);
+
+ if((old=pthread_getspecific(LocalContext)) != NULL)
{
pthread_setspecific(LocalContext, NULL);
- ALCcontext_DecRef(context);
+ ALCcontext_DecRef(old);
}
}
else