aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
Diffstat (limited to 'alc')
-rw-r--r--alc/alc.cpp17
-rw-r--r--alc/alcmain.h9
-rw-r--r--alc/backends/base.cpp3
3 files changed, 15 insertions, 14 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index e03dc2f6..0962276d 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -1679,9 +1679,7 @@ void ALCcontext::allocVoices(size_t addcount)
if(auto *oldvoices = mVoices.exchange(newarray.release(), std::memory_order_acq_rel))
{
- ALuint refcount;
- while((refcount=mDevice->MixCount.load(std::memory_order_acquire))&1)
- std::this_thread::yield();
+ mDevice->waitForMix();
delete oldvoices;
}
}
@@ -2675,8 +2673,7 @@ bool ALCcontext::deinit()
mDevice->mContexts.store(newarray);
if(oldarray != &EmptyContextArray)
{
- while((mDevice->MixCount.load(std::memory_order_acquire)&1))
- std::this_thread::yield();
+ mDevice->waitForMix();
delete oldarray;
}
@@ -3321,8 +3318,7 @@ START_API_FUNC
ALuint samplecount;
ALuint refcount;
do {
- while(((refcount=ReadRef(dev->MixCount))&1) != 0)
- std::this_thread::yield();
+ refcount = dev->waitForMix();
basecount = dev->ClockBase;
samplecount = dev->SamplesDone;
} while(refcount != ReadRef(dev->MixCount));
@@ -3516,8 +3512,7 @@ START_API_FUNC
dev->mContexts.store(newarray.release());
if(oldarray != &EmptyContextArray)
{
- while((dev->MixCount.load(std::memory_order_acquire)&1))
- std::this_thread::yield();
+ dev->waitForMix();
delete oldarray;
}
}
@@ -4349,9 +4344,7 @@ START_API_FUNC
if(!dev->Connected.load(std::memory_order_relaxed))
{
/* Make sure disconnection is finished before continuing on. */
- ALuint refcount;
- while(((refcount=dev->MixCount.load(std::memory_order_acquire))&1))
- std::this_thread::yield();
+ dev->waitForMix();
for(ALCcontext *ctx : *dev->mContexts.load(std::memory_order_acquire))
{
diff --git a/alc/alcmain.h b/alc/alcmain.h
index 071e43f5..1560b831 100644
--- a/alc/alcmain.h
+++ b/alc/alcmain.h
@@ -10,6 +10,7 @@
#include <memory>
#include <mutex>
#include <string>
+#include <thread>
#include <utility>
#include "AL/al.h"
@@ -356,6 +357,14 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> {
ALuint channelsFromFmt() const noexcept { return ChannelsFromDevFmt(FmtChans, mAmbiOrder); }
ALuint frameSizeFromFmt() const noexcept { return bytesFromFmt() * channelsFromFmt(); }
+ ALuint waitForMix() const noexcept
+ {
+ ALuint refcount;
+ while((refcount=MixCount.load(std::memory_order_acquire))&1)
+ std::this_thread::yield();
+ return refcount;
+ }
+
void ProcessHrtf(const size_t SamplesToDo);
void ProcessAmbiDec(const size_t SamplesToDo);
void ProcessUhj(const size_t SamplesToDo);
diff --git a/alc/backends/base.cpp b/alc/backends/base.cpp
index 25531cf5..f79f2063 100644
--- a/alc/backends/base.cpp
+++ b/alc/backends/base.cpp
@@ -44,8 +44,7 @@ ClockLatency BackendBase::getClockLatency()
ALuint refcount;
do {
- while(((refcount=ReadRef(mDevice->MixCount))&1) != 0)
- std::this_thread::yield();
+ refcount = mDevice->waitForMix();
ret.ClockTime = GetDeviceClockTime(mDevice);
std::atomic_thread_fence(std::memory_order_acquire);
} while(refcount != ReadRef(mDevice->MixCount));