diff options
author | Chris Robinson <[email protected]> | 2017-03-05 04:50:27 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-03-05 04:50:27 -0800 |
commit | 073829f26a4a509d11de5375d43169a8f6ba9e12 (patch) | |
tree | 28a341bd1a5954ff9e94a3332bc843314c52f2d0 | |
parent | c0404916150c48769d08ac32921b9a6a66dc0c0a (diff) |
Make the voice's source pointer atomic
-rw-r--r-- | Alc/ALc.c | 2 | ||||
-rw-r--r-- | Alc/ALu.c | 12 | ||||
-rw-r--r-- | OpenAL32/Include/alSource.h | 2 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 16 |
4 files changed, 17 insertions, 15 deletions
@@ -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); @@ -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); |