diff options
Diffstat (limited to 'alc/alu.cpp')
-rw-r--r-- | alc/alu.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/alc/alu.cpp b/alc/alu.cpp index e0858b18..23518fa9 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -1910,8 +1910,9 @@ void ProcessContexts(DeviceBase *device, const uint SamplesToDo) { ASSUME(SamplesToDo > 0); - const nanoseconds curtime{device->ClockBase + - nanoseconds{seconds{device->SamplesDone}}/device->Frequency}; + const nanoseconds curtime{device->mClockBase.load(std::memory_order_relaxed) + + nanoseconds{seconds{device->mSamplesDone.load(std::memory_order_relaxed)}}/ + device->Frequency}; for(ContextBase *ctx : *device->mContexts.load(std::memory_order_acquire)) { @@ -2135,7 +2136,9 @@ uint DeviceBase::renderSamples(const uint numSamples) buffer.fill(0.0f); /* Increment the mix count at the start (lsb should now be 1). */ - IncrementRef(MixCount); + const auto mixCount = MixCount.load(std::memory_order_relaxed); + MixCount.store(mixCount+1, std::memory_order_relaxed); + std::atomic_thread_fence(std::memory_order_release); /* Process and mix each context's sources and effects. */ ProcessContexts(this, samplesToDo); @@ -2144,12 +2147,16 @@ uint DeviceBase::renderSamples(const uint numSamples) * and added to clock base so that large sample counts don't overflow * during conversion. This also guarantees a stable conversion. */ - SamplesDone += samplesToDo; - ClockBase += std::chrono::seconds{SamplesDone / Frequency}; - SamplesDone %= Frequency; + { + auto samplesDone = mSamplesDone.load(std::memory_order_relaxed) + samplesToDo; + auto clockBase = mClockBase.load(std::memory_order_relaxed) + + std::chrono::seconds{samplesDone/Frequency}; + mSamplesDone.store(samplesDone%Frequency, std::memory_order_relaxed); + mClockBase.store(clockBase, std::memory_order_relaxed); + } /* Increment the mix count at the end (lsb should now be 0). */ - IncrementRef(MixCount); + MixCount.store(mixCount+2, std::memory_order_release); /* Apply any needed post-process for finalizing the Dry mix to the RealOut * (Ambisonic decode, UHJ encode, etc). @@ -2225,7 +2232,10 @@ void DeviceBase::renderSamples(void *outBuffer, const uint numSamples, const siz void DeviceBase::handleDisconnect(const char *msg, ...) { - IncrementRef(MixCount); + const auto mixCount = MixCount.load(std::memory_order_relaxed); + MixCount.store(mixCount+1, std::memory_order_relaxed); + std::atomic_thread_fence(std::memory_order_release); + if(Connected.exchange(false, std::memory_order_acq_rel)) { AsyncEvent evt{std::in_place_type<AsyncDisconnectEvent>}; @@ -2267,5 +2277,6 @@ void DeviceBase::handleDisconnect(const char *msg, ...) std::for_each(voicelist.begin(), voicelist.end(), stop_voice); } } - IncrementRef(MixCount); + + MixCount.store(mixCount+2, std::memory_order_release); } |