From 8ca8da30bd587cefcd86e3a2b9401821af65e502 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 29 Nov 2018 22:49:01 -0800 Subject: Store the source ID with the voice instead of the source pointer --- Alc/alc.cpp | 2 +- Alc/alu.cpp | 22 +++++++++++----------- OpenAL32/Include/alu.h | 2 +- OpenAL32/alSource.cpp | 16 +++++++++------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Alc/alc.cpp b/Alc/alc.cpp index aa786244..d8e35d29 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2332,7 +2332,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) { al_free(voice->Update.exchange(nullptr, std::memory_order_acq_rel)); - if(voice->Source.load(std::memory_order_acquire) == nullptr) + if(voice->SourceID.load(std::memory_order_acquire) == 0u) return; if(device->AvgSpeakerDist > 0.0f) diff --git a/Alc/alu.cpp b/Alc/alu.cpp index ecf5f024..607798ba 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -1506,8 +1506,8 @@ void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray *slots) std::for_each(ctx->Voices, ctx->Voices+ctx->VoiceCount.load(std::memory_order_acquire), [ctx,force](ALvoice *voice) -> void { - ALsource *source{voice->Source.load(std::memory_order_acquire)}; - if(source) CalcSourceParams(voice, ctx, force); + ALuint sid{voice->SourceID.load(std::memory_order_acquire)}; + if(sid) CalcSourceParams(voice, ctx, force); } ); } @@ -1536,16 +1536,16 @@ void ProcessContext(ALCcontext *ctx, ALsizei SamplesToDo) std::for_each(ctx->Voices, ctx->Voices+ctx->VoiceCount.load(std::memory_order_acquire), [SamplesToDo,ctx](ALvoice *voice) -> void { - ALsource *source{voice->Source.load(std::memory_order_acquire)}; - if(!source) return; + ALuint sid{voice->SourceID.load(std::memory_order_acquire)}; + if(!sid) return; if(!voice->Playing.load(std::memory_order_relaxed) || voice->Step < 1) return; - if(!MixSource(voice, source->id, ctx, SamplesToDo)) + if(!MixSource(voice, sid, ctx, SamplesToDo)) { - voice->Source.store(nullptr, std::memory_order_relaxed); + voice->SourceID.store(0u, std::memory_order_relaxed); voice->Playing.store(false, std::memory_order_release); - SendSourceStoppedEvent(ctx, source->id); + SendSourceStoppedEvent(ctx, sid); } } ); @@ -1862,17 +1862,17 @@ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) std::for_each(ctx->Voices, ctx->Voices+ctx->VoiceCount.load(std::memory_order_acquire), [ctx](ALvoice *voice) -> void { - ALsource *source{voice->Source.load(std::memory_order_relaxed)}; - if(!source || !voice->Playing.load(std::memory_order_relaxed)) + ALuint sid{voice->SourceID.load(std::memory_order_relaxed)}; + if(!sid || !voice->Playing.load(std::memory_order_relaxed)) return; - voice->Source.store(nullptr, std::memory_order_relaxed); + voice->SourceID.store(0u, std::memory_order_relaxed); voice->Playing.store(false, std::memory_order_release); /* If the source's voice was playing, it's now effectively * stopped (the source state will be updated the next time it's * checked). */ - SendSourceStoppedEvent(ctx, source->id); + SendSourceStoppedEvent(ctx, sid); } ); diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 68f539f3..e178a5a6 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -207,7 +207,7 @@ typedef struct ALvoice { std::atomic Update; - std::atomic Source; + std::atomic SourceID; std::atomic Playing; /** diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp index a60701e7..9911bcc5 100644 --- a/OpenAL32/alSource.cpp +++ b/OpenAL32/alSource.cpp @@ -52,10 +52,11 @@ namespace { inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) { ALint idx{source->VoiceIdx}; + ALuint sid{source->id}; if(idx >= 0 && idx < context->VoiceCount.load(std::memory_order_relaxed)) { ALvoice *voice{context->Voices[idx]}; - if(voice->Source.load(std::memory_order_acquire) == source) + if(voice->SourceID.load(std::memory_order_acquire) == sid) return voice; } source->VoiceIdx = -1; @@ -525,7 +526,7 @@ void FreeSource(ALCcontext *context, ALsource *source) ALvoice *voice{GetSourceVoice(source, context)}; if(voice) { - voice->Source.store(nullptr, std::memory_order_relaxed); + voice->SourceID.store(0u, std::memory_order_relaxed); voice->Playing.store(false, std::memory_order_release); } ALCdevice_Unlock(device); @@ -2782,7 +2783,7 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) auto voices_end = context->Voices + context->VoiceCount.load(std::memory_order_relaxed); auto voice_iter = std::find_if(context->Voices, voices_end, [](const ALvoice *voice) noexcept -> bool - { return voice->Source.load(std::memory_order_relaxed) == nullptr; } + { return voice->SourceID.load(std::memory_order_relaxed) == 0u; } ); auto vidx = static_cast(std::distance(context->Voices, voice_iter)); voice = *voice_iter; @@ -2841,7 +2842,7 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) NfcFilterCreate(&voice->Direct.Params[j].NFCtrlFilter, 0.0f, w1); } - voice->Source.store(source, std::memory_order_relaxed); + voice->SourceID.store(source->id, std::memory_order_relaxed); voice->Playing.store(true, std::memory_order_release); source->state = AL_PLAYING; source->VoiceIdx = vidx; @@ -2913,7 +2914,7 @@ AL_API ALvoid AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources) ALvoice *voice{GetSourceVoice(source, context.get())}; if(voice != nullptr) { - voice->Source.store(nullptr, std::memory_order_relaxed); + voice->SourceID.store(0u, std::memory_order_relaxed); voice->Playing.store(false, std::memory_order_release); voice = nullptr; } @@ -2956,7 +2957,7 @@ AL_API ALvoid AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources) ALvoice *voice{GetSourceVoice(source, context.get())}; if(voice != nullptr) { - voice->Source.store(nullptr, std::memory_order_relaxed); + voice->SourceID.store(0u, std::memory_order_relaxed); voice->Playing.store(false, std::memory_order_release); voice = nullptr; } @@ -3389,7 +3390,8 @@ void UpdateAllSourceProps(ALCcontext *context) std::for_each(context->Voices, voices_end, [context](ALvoice *voice) -> void { - ALsource *source{voice->Source.load(std::memory_order_acquire)}; + ALuint sid{voice->SourceID.load(std::memory_order_acquire)}; + ALsource *source = sid ? LookupSource(context, sid) : nullptr; if(source && !source->PropsClean.test_and_set(std::memory_order_acq_rel)) UpdateSourceProps(source, voice, context); } -- cgit v1.2.3