Remove althrd_yield
[openal-soft.git] / Alc / backends / base.cpp
blob85f4b03485baba625b7120c26054b9b41d4793a5
2 #include "config.h"
4 #include <stdlib.h>
6 #include <thread>
8 #include "alMain.h"
9 #include "alu.h"
11 #include "backends/base.h"
14 void ALCdevice_Lock(ALCdevice *device)
15 { V0(device->Backend,lock)(); }
17 void ALCdevice_Unlock(ALCdevice *device)
18 { V0(device->Backend,unlock)(); }
20 ClockLatency GetClockLatency(ALCdevice *device)
22 ClockLatency ret = V0(device->Backend,getClockLatency)();
23 ret.Latency += device->FixedLatency;
24 return ret;
28 /* Base ALCbackend method implementations. */
29 void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
31 self->mDevice = device;
34 void ALCbackend_Destruct(ALCbackend* UNUSED(self))
38 ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self))
40 return ALC_FALSE;
43 ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
45 return ALC_INVALID_DEVICE;
48 ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self))
50 return 0;
53 ClockLatency ALCbackend_getClockLatency(ALCbackend *self)
55 ALCdevice *device = self->mDevice;
56 ALuint refcount;
57 ClockLatency ret;
59 do {
60 while(((refcount=device->MixCount.load(std::memory_order_acquire))&1))
61 std::this_thread::yield();
62 ret.ClockTime = GetDeviceClockTime(device);
63 std::atomic_thread_fence(std::memory_order_acquire);
64 } while(refcount != device->MixCount.load(std::memory_order_relaxed));
66 /* NOTE: The device will generally have about all but one periods filled at
67 * any given time during playback. Without a more accurate measurement from
68 * the output, this is an okay approximation.
70 ret.Latency = std::chrono::seconds{device->UpdateSize*maxi(device->NumUpdates-1, 0)};
71 ret.Latency /= device->Frequency;
73 return ret;
76 void ALCbackend_lock(ALCbackend *self)
78 try {
79 self->mMutex.lock();
81 catch(...) {
82 std::terminate();
86 void ALCbackend_unlock(ALCbackend *self)
88 try {
89 self->mMutex.unlock();
91 catch(...) {
92 std::terminate();