Lock the context as needed for the defer and process calls
This commit is contained in:
@@ -1361,14 +1361,14 @@ static ALCvoid FreeContext(ALCcontext *context)
|
||||
free(context);
|
||||
}
|
||||
|
||||
static void ALCcontext_IncRef(ALCcontext *context)
|
||||
void ALCcontext_IncRef(ALCcontext *context)
|
||||
{
|
||||
RefCount ref;
|
||||
ref = IncrementRef(&context->ref);
|
||||
TRACE("%p refcount increment to %d\n", context, ref);
|
||||
}
|
||||
|
||||
static void ALCcontext_DecRef(ALCcontext *context)
|
||||
void ALCcontext_DecRef(ALCcontext *context)
|
||||
{
|
||||
RefCount ref;
|
||||
ref = DecrementRef(&context->ref);
|
||||
@@ -1418,6 +1418,30 @@ ALCcontext *GetLockedContext(void)
|
||||
return context;
|
||||
}
|
||||
|
||||
/*
|
||||
* GetReffedContext(void)
|
||||
*
|
||||
* Returns the currently active Context, and add a reference to it without
|
||||
* locking
|
||||
*/
|
||||
ALCcontext *GetReffedContext(void)
|
||||
{
|
||||
ALCcontext *context;
|
||||
|
||||
context = pthread_getspecific(LocalContext);
|
||||
if(context)
|
||||
ALCcontext_IncRef(context);
|
||||
else
|
||||
{
|
||||
LockLists();
|
||||
context = GlobalContext;
|
||||
if(context)
|
||||
ALCcontext_IncRef(context);
|
||||
UnlockLists();
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -571,6 +571,9 @@ struct ALCcontext_struct
|
||||
ALCcontext *next;
|
||||
};
|
||||
|
||||
void ALCcontext_IncRef(ALCcontext *context);
|
||||
void ALCcontext_DecRef(ALCcontext *context);
|
||||
|
||||
void AppendDeviceList(const ALCchar *name);
|
||||
void AppendAllDeviceList(const ALCchar *name);
|
||||
void AppendCaptureDeviceList(const ALCchar *name);
|
||||
@@ -586,6 +589,7 @@ ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
|
||||
ALuint StopThread(ALvoid *thread);
|
||||
|
||||
ALCcontext *GetLockedContext(void);
|
||||
ALCcontext *GetReffedContext(void);
|
||||
|
||||
typedef struct RingBuffer RingBuffer;
|
||||
RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
|
||||
|
||||
+10
-9
@@ -577,7 +577,7 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
Context = GetLockedContext();
|
||||
Context = GetReffedContext();
|
||||
if(!Context) return;
|
||||
|
||||
if(!Context->DeferUpdates)
|
||||
@@ -587,11 +587,11 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
|
||||
ALeffectslot *ALEffectSlot;
|
||||
ALsizei e;
|
||||
|
||||
LockContext(Context);
|
||||
Context->DeferUpdates = AL_TRUE;
|
||||
|
||||
/* Make sure all pending updates are performed */
|
||||
UpdateSources = Context->UpdateSources;
|
||||
Context->UpdateSources = AL_FALSE;
|
||||
UpdateSources = Exchange_ALenum(&Context->UpdateSources, AL_FALSE);
|
||||
|
||||
src = Context->ActiveSources;
|
||||
src_end = src + Context->ActiveSourceCount;
|
||||
@@ -616,24 +616,24 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
|
||||
if(Exchange_ALenum(&ALEffectSlot->NeedsUpdate, AL_FALSE))
|
||||
ALEffect_Update(ALEffectSlot->EffectState, Context, ALEffectSlot);
|
||||
}
|
||||
UnlockContext(Context);
|
||||
}
|
||||
|
||||
UnlockContext(Context);
|
||||
ALCcontext_DecRef(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
Context = GetLockedContext();
|
||||
Context = GetReffedContext();
|
||||
if(!Context) return;
|
||||
|
||||
if(Context->DeferUpdates)
|
||||
if(Exchange_ALenum(&Context->DeferUpdates, AL_FALSE))
|
||||
{
|
||||
ALsizei pos;
|
||||
|
||||
Context->DeferUpdates = AL_FALSE;
|
||||
|
||||
LockContext(Context);
|
||||
for(pos = 0;pos < Context->SourceMap.size;pos++)
|
||||
{
|
||||
ALsource *Source = Context->SourceMap.array[pos].value;
|
||||
@@ -647,7 +647,8 @@ AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)
|
||||
if(new_state)
|
||||
SetSourceState(Source, Context, new_state);
|
||||
}
|
||||
UnlockContext(Context);
|
||||
}
|
||||
|
||||
UnlockContext(Context);
|
||||
ALCcontext_DecRef(Context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user