ClockLatency ALCbackend_getClockLatency(ALCbackend *self) { ALCdevice *device = self->mDevice; ClockLatency ret; almtx_lock(&self->mMutex); ret.ClockTime = GetDeviceClockTime(device); // TODO: Perhaps should be NumUpdates-1 worth of UpdateSize? ret.Latency = 0; almtx_unlock(&self->mMutex); return ret; }
ClockLatency BackendBase::getClockLatency() { ClockLatency ret; ALuint refcount; do { while(((refcount=mDevice->MixCount.load(std::memory_order_acquire))&1)) std::this_thread::yield(); ret.ClockTime = GetDeviceClockTime(mDevice); std::atomic_thread_fence(std::memory_order_acquire); } while(refcount != mDevice->MixCount.load(std::memory_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 = std::chrono::seconds{maxi(mDevice->BufferSize-mDevice->UpdateSize, 0)}; ret.Latency /= mDevice->Frequency; return ret; }