aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/ALc.c2
-rw-r--r--Alc/ALu.c12
-rw-r--r--OpenAL32/Include/alSource.h2
-rw-r--r--OpenAL32/alSource.c16
4 files changed, 17 insertions, 15 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 59475e48..42e1cea0 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1721,7 +1721,7 @@ void ALCcontext_ProcessUpdates(ALCcontext *context)
for(pos = 0;pos < context->VoiceCount;pos++)
{
ALvoice *voice = context->Voices[pos];
- ALsource *source = voice->Source;
+ ALsource *source = ATOMIC_LOAD(&voice->Source, almemory_order_acquire);
if(source && source->OffsetType != AL_NONE)
{
WriteLock(&source->queue_lock);
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 0a1b919a..e14c2013 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -1277,8 +1277,8 @@ static void UpdateContextSources(ALCcontext *ctx, ALeffectslot *slot)
voice_end = voice + ctx->VoiceCount;
for(;voice != voice_end;++voice)
{
- if((source=(*voice)->Source) != NULL)
- CalcSourceParams(*voice, source, ctx, force);
+ source = ATOMIC_LOAD(&(*voice)->Source, almemory_order_acquire);
+ if(source) CalcSourceParams(*voice, source, ctx, force);
}
}
IncrementRef(&ctx->UpdateCount);
@@ -1419,13 +1419,13 @@ void aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
voice_end = voice + ctx->VoiceCount;
for(;voice != voice_end;++voice)
{
- source = (*voice)->Source;
+ source = ATOMIC_LOAD(&(*voice)->Source, almemory_order_acquire);
if(source && ATOMIC_LOAD(&(*voice)->Playing, almemory_order_relaxed) &&
(*voice)->Step > 0)
{
if(!MixSource(*voice, source, device, SamplesToDo))
{
- (*voice)->Source = NULL;
+ ATOMIC_STORE(&(*voice)->Source, NULL, almemory_order_relaxed);
ATOMIC_STORE(&(*voice)->Playing, false, almemory_order_release);
}
}
@@ -1592,8 +1592,8 @@ void aluHandleDisconnect(ALCdevice *device)
voice_end = voice + Context->VoiceCount;
while(voice != voice_end)
{
- ALsource *source = (*voice)->Source;
- (*voice)->Source = NULL;
+ ALsource *source = ATOMIC_EXCHANGE(ALsource*, &(*voice)->Source, NULL,
+ almemory_order_acq_rel);
ATOMIC_STORE(&(*voice)->Playing, false, almemory_order_release);
if(source)
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h
index fc1756e5..52fe731e 100644
--- a/OpenAL32/Include/alSource.h
+++ b/OpenAL32/Include/alSource.h
@@ -80,7 +80,7 @@ struct ALsourceProps {
typedef struct ALvoice {
struct ALsourceProps *Props;
- struct ALsource *Source;
+ ATOMIC(struct ALsource*) Source;
ATOMIC(bool) Playing;
/* Current buffer queue item being played. */
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 14329bc2..df0e7136 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -132,7 +132,7 @@ static inline ALvoice *GetSourceVoice(const ALsource *source, const ALCcontext *
ALvoice **voice_end = voice + context->VoiceCount;
while(voice != voice_end)
{
- if((*voice)->Source == source)
+ if(ATOMIC_LOAD(&(*voice)->Source, almemory_order_acquire) == source)
return *voice;
++voice;
}
@@ -1639,7 +1639,7 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
ALCdevice_Lock(device);
if((voice=GetSourceVoice(Source, context)) != NULL)
{
- voice->Source = NULL;
+ ATOMIC_STORE(&voice->Source, NULL, almemory_order_relaxed);
ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
}
ALCdevice_Unlock(device);
@@ -2950,7 +2950,7 @@ void UpdateAllSourceProps(ALCcontext *context)
for(pos = 0;pos < context->VoiceCount;pos++)
{
ALvoice *voice = context->Voices[pos];
- ALsource *source = voice->Source;
+ ALsource *source = ATOMIC_LOAD(&voice->Source, almemory_order_acquire);
if(source != NULL && source->NeedsUpdate && IsPlayingOrPausedSeq(source))
{
source->NeedsUpdate = AL_FALSE;
@@ -3028,7 +3028,7 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
assert(voice == NULL);
for(i = 0;i < Context->VoiceCount;i++)
{
- if(Context->Voices[i]->Source == NULL)
+ if(ATOMIC_LOAD(&Context->Voices[i]->Source, almemory_order_acquire) == NULL)
{
voice = Context->Voices[i];
break;
@@ -3069,7 +3069,7 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
}
}
- voice->Source = Source;
+ ATOMIC_STORE(&voice->Source, Source, almemory_order_relaxed);
ATOMIC_STORE(&voice->Playing, true, almemory_order_release);
}
else if(state == AL_PAUSED)
@@ -3088,7 +3088,7 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
do_stop:
if((voice=GetSourceVoice(Source, Context)) != NULL)
{
- voice->Source = NULL;
+ ATOMIC_STORE(&voice->Source, NULL, almemory_order_relaxed);
ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
althrd_yield();
@@ -3102,7 +3102,7 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
{
if((voice=GetSourceVoice(Source, Context)) != NULL)
{
- voice->Source = NULL;
+ ATOMIC_STORE(&voice->Source, NULL, almemory_order_relaxed);
ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
althrd_yield();
@@ -3257,6 +3257,8 @@ static ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *conte
BufferList = ATOMIC_LOAD(&Source->queue, almemory_order_relaxed);
looping = ATOMIC_LOAD(&Source->looping, almemory_order_relaxed);
do {
+ Current = NULL;
+ readPos = readPosFrac = 0;
while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
althrd_yield();
voice = GetSourceVoice(Source, context);