aboutsummaryrefslogtreecommitdiffstats
path: root/alc/alu.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-12-04 01:18:49 -0800
committerChris Robinson <[email protected]>2023-12-04 02:25:05 -0800
commite123e7bbda4330559ef03a5362bc93064eb87e4e (patch)
tree5dc77aeefd6ae7576f8cc8fb0b7c5a35ad7ee46d /alc/alu.cpp
parentb6a68e8d510610e181d638ff993e327059bd6018 (diff)
Use RAII to handle writing under the mixer seqlock
Diffstat (limited to 'alc/alu.cpp')
-rw-r--r--alc/alu.cpp28
1 files changed, 9 insertions, 19 deletions
diff --git a/alc/alu.cpp b/alc/alu.cpp
index 23518fa9..2bc648bf 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -2135,19 +2135,16 @@ uint DeviceBase::renderSamples(const uint numSamples)
for(FloatBufferLine &buffer : MixBuffer)
buffer.fill(0.0f);
- /* Increment the mix count at the start (lsb should now be 1). */
- 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);
+ {
+ const auto mixLock = getWriteMixLock();
- /* Process and mix each context's sources and effects. */
- ProcessContexts(this, samplesToDo);
+ /* Process and mix each context's sources and effects. */
+ ProcessContexts(this, samplesToDo);
- /* Increment the clock time. Every second's worth of samples is converted
- * and added to clock base so that large sample counts don't overflow
- * during conversion. This also guarantees a stable conversion.
- */
- {
+ /* Every second's worth of samples is converted and added to clock base
+ * so that large sample counts don't overflow during conversion. This
+ * also guarantees a stable conversion.
+ */
auto samplesDone = mSamplesDone.load(std::memory_order_relaxed) + samplesToDo;
auto clockBase = mClockBase.load(std::memory_order_relaxed) +
std::chrono::seconds{samplesDone/Frequency};
@@ -2155,9 +2152,6 @@ uint DeviceBase::renderSamples(const uint numSamples)
mClockBase.store(clockBase, std::memory_order_relaxed);
}
- /* Increment the mix count at the end (lsb should now be 0). */
- 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).
*/
@@ -2232,9 +2226,7 @@ void DeviceBase::renderSamples(void *outBuffer, const uint numSamples, const siz
void DeviceBase::handleDisconnect(const char *msg, ...)
{
- 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);
+ const auto mixLock = getWriteMixLock();
if(Connected.exchange(false, std::memory_order_acq_rel))
{
@@ -2277,6 +2269,4 @@ void DeviceBase::handleDisconnect(const char *msg, ...)
std::for_each(voicelist.begin(), voicelist.end(), stop_voice);
}
}
-
- MixCount.store(mixCount+2, std::memory_order_release);
}