Remove the last remaining uses of althrd_t
[openal-soft.git] / Alc / backends / base.cpp
blobe4c7588c713762b760bcbddf5a9535daf7d5bf63
2 #include "config.h"
4 #include <stdlib.h>
6 #include "alMain.h"
7 #include "alu.h"
9 #include "backends/base.h"
12 void ALCdevice_Lock(ALCdevice *device)
13 { V0(device->Backend,lock)(); }
15 void ALCdevice_Unlock(ALCdevice *device)
16 { V0(device->Backend,unlock)(); }
18 ClockLatency GetClockLatency(ALCdevice *device)
20 ClockLatency ret = V0(device->Backend,getClockLatency)();
21 ret.Latency += device->FixedLatency;
22 return ret;
26 /* Base ALCbackend method implementations. */
27 void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
29 self->mDevice = device;
32 void ALCbackend_Destruct(ALCbackend* UNUSED(self))
36 ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self))
38 return ALC_FALSE;
41 ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
43 return ALC_INVALID_DEVICE;
46 ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self))
48 return 0;
51 ClockLatency ALCbackend_getClockLatency(ALCbackend *self)
53 ALCdevice *device = self->mDevice;
54 ALuint refcount;
55 ClockLatency ret;
57 do {
58 while(((refcount=device->MixCount.load(std::memory_order_acquire))&1))
59 althrd_yield();
60 ret.ClockTime = GetDeviceClockTime(device);
61 std::atomic_thread_fence(std::memory_order_acquire);
62 } while(refcount != device->MixCount.load(std::memory_order_relaxed));
64 /* NOTE: The device will generally have about all but one periods filled at
65 * any given time during playback. Without a more accurate measurement from
66 * the output, this is an okay approximation.
68 ret.Latency = std::chrono::seconds{device->UpdateSize*maxi(device->NumUpdates-1, 0)};
69 ret.Latency /= device->Frequency;
71 return ret;
74 void ALCbackend_lock(ALCbackend *self)
76 try {
77 self->mMutex.lock();
79 catch(...) {
80 std::terminate();
84 void ALCbackend_unlock(ALCbackend *self)
86 try {
87 self->mMutex.unlock();
89 catch(...) {
90 std::terminate();