diff options
author | Chris Robinson <[email protected]> | 2009-08-16 14:09:23 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2009-08-16 14:09:23 -0700 |
commit | 462f27c129454b71179e0ebce366f3b8d7956da6 (patch) | |
tree | 7d726be69bdac1c6ed6354c52057d747be9a9359 /Alc/ALc.c | |
parent | 2d1191697ae5a770b7e0b57a612271ef70b6b890 (diff) |
Use a function to retrieve the current context in an already-locked state
This should help prevent race-conditions with a context being destroyed between
breing retrieved and locked
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r-- | Alc/ALc.c | 31 |
1 files changed, 27 insertions, 4 deletions
@@ -454,6 +454,30 @@ ALCvoid ProcessContext(ALCcontext *pContext) /* + GetContextSuspended + + Returns the currently active Context, in a locked state +*/ +ALCcontext *GetContextSuspended(void) +{ + ALCcontext *pContext = NULL; + + SuspendContext(NULL); + + pContext = g_pContextList; + while(pContext && !pContext->InUse) + pContext = pContext->next; + + if(pContext) + SuspendContext(pContext); + + ProcessContext(NULL); + + return pContext; +} + + +/* InitContext Initialize Context variables @@ -1236,16 +1260,15 @@ ALCAPI ALCboolean ALCAPIENTRY alcMakeContextCurrent(ALCcontext *context) SuspendContext(NULL); // context must be a valid Context or NULL - if ((IsContext(context)) || (context == NULL)) + if(context == NULL || IsContext(context)) { - if ((ALContext=alcGetCurrentContext())) + if((ALContext=GetContextSuspended()) != NULL) { - SuspendContext(ALContext); ALContext->InUse=AL_FALSE; ProcessContext(ALContext); } - if ((ALContext=context) && (ALContext->Device)) + if((ALContext=context) != NULL && ALContext->Device) { SuspendContext(ALContext); ALContext->InUse=AL_TRUE; |