aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-08-29 13:22:07 -0700
committerChris Robinson <[email protected]>2011-08-29 13:22:07 -0700
commit72beb577b6190d9df0426825f131a5c8624aaeec (patch)
treefbc6653d88aee582cc7a5751ecc48762c82fa544
parentde65ee08c9c3b2261b8329d45cb57b4b4e5cb6a1 (diff)
Lock the context as needed for the defer and process calls
-rw-r--r--Alc/ALc.c28
-rw-r--r--OpenAL32/Include/alMain.h4
-rw-r--r--OpenAL32/alState.c19
3 files changed, 40 insertions, 11 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 9929ee3b..892ccc41 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -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;
+}
///////////////////////////////////////////////////////
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index b0a33114..a9f5813d 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -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);
diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c
index 7e73f407..a65eaa82 100644
--- a/OpenAL32/alState.c
+++ b/OpenAL32/alState.c
@@ -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);
}