From 1cd6617ff6404cfdcc1ccaf1c08c9d763e27366c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 28 Feb 2017 03:50:42 -0800 Subject: Don't use the mutex in the base getClockLatency implementation --- Alc/backends/base.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Alc') diff --git a/Alc/backends/base.c b/Alc/backends/base.c index e4305653..902c4310 100644 --- a/Alc/backends/base.c +++ b/Alc/backends/base.c @@ -42,17 +42,22 @@ ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self)) ClockLatency ALCbackend_getClockLatency(ALCbackend *self) { ALCdevice *device = self->mDevice; + ALuint refcount; ClockLatency ret; - almtx_lock(&self->mMutex); - ret.ClockTime = GetDeviceClockTime(device); + do { + while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1)) + althrd_yield(); + ret.ClockTime = GetDeviceClockTime(device); + ATOMIC_THREAD_FENCE(almemory_order_acquire); + } while(refcount != ATOMIC_LOAD(&device->MixCount, almemory_order_relaxed)); + /* NOTE: The device will generally have about all but one periods filled at * any given time during playback. Without a more accurate measurement from * the output, this is an okay approximation. */ ret.Latency = device->UpdateSize * DEVICE_CLOCK_RES / device->Frequency * maxu(device->NumUpdates-1, 1); - almtx_unlock(&self->mMutex); return ret; } -- cgit v1.2.3