aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2009-08-16 14:09:23 -0700
committerChris Robinson <[email protected]>2009-08-16 14:09:23 -0700
commit462f27c129454b71179e0ebce366f3b8d7956da6 (patch)
tree7d726be69bdac1c6ed6354c52057d747be9a9359 /Alc
parent2d1191697ae5a770b7e0b57a612271ef70b6b890 (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')
-rw-r--r--Alc/ALc.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 30d502d0..a807ef47 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -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;