Store the source ID with the voice instead of the source pointer
This commit is contained in:
+1
-1
@@ -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)
|
||||
|
||||
+11
-11
@@ -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);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ typedef struct ALvoice {
|
||||
|
||||
std::atomic<ALvoiceProps*> Update;
|
||||
|
||||
std::atomic<ALsource*> Source;
|
||||
std::atomic<ALuint> SourceID;
|
||||
std::atomic<bool> Playing;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<ALint>(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user