From 09ea1d58f63ad3fe248b1e59c0a3634447ce672d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 13 Nov 2018 01:39:42 -0800 Subject: Convert the backend base to C++ --- Alc/ALc.c | 5 +++ Alc/backends/base.c | 84 --------------------------------------------------- Alc/backends/base.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 84 deletions(-) delete mode 100644 Alc/backends/base.c create mode 100644 Alc/backends/base.cpp (limited to 'Alc') diff --git a/Alc/ALc.c b/Alc/ALc.c index 4e2402ca..cc51a3d7 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1589,6 +1589,11 @@ extern inline void UnlockBufferList(ALCdevice *device); extern inline ALsizei FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType type); extern inline ALsizei FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type); +extern inline ALuint64 GetDeviceClockTime(ALCdevice *device); +extern inline void ALCdevice_Lock(ALCdevice *device); +extern inline void ALCdevice_Unlock(ALCdevice *device); +extern inline ClockLatency GetClockLatency(ALCdevice *device); + extern inline void alstr_reset(al_string *str); extern inline size_t alstr_length(const_al_string str); extern inline ALboolean alstr_empty(const_al_string str); diff --git a/Alc/backends/base.c b/Alc/backends/base.c deleted file mode 100644 index 9d8614b1..00000000 --- a/Alc/backends/base.c +++ /dev/null @@ -1,84 +0,0 @@ - -#include "config.h" - -#include - -#include "alMain.h" -#include "alu.h" - -#include "backends/base.h" - - -extern inline ALuint64 GetDeviceClockTime(ALCdevice *device); -extern inline void ALCdevice_Lock(ALCdevice *device); -extern inline void ALCdevice_Unlock(ALCdevice *device); -extern inline ClockLatency GetClockLatency(ALCdevice *device); - -/* Base ALCbackend method implementations. */ -void ALCbackend_Construct(ALCbackend *self, ALCdevice *device) -{ - int ret = almtx_init(&self->mMutex, almtx_recursive); - assert(ret == althrd_success); - self->mDevice = device; -} - -void ALCbackend_Destruct(ALCbackend *self) -{ - almtx_destroy(&self->mMutex); -} - -ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self)) -{ - return ALC_FALSE; -} - -ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples)) -{ - return ALC_INVALID_DEVICE; -} - -ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self)) -{ - return 0; -} - -ClockLatency ALCbackend_getClockLatency(ALCbackend *self) -{ - ALCdevice *device = self->mDevice; - ALuint refcount; - ClockLatency ret; - - 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); - - return ret; -} - -void ALCbackend_lock(ALCbackend *self) -{ - int ret = almtx_lock(&self->mMutex); - assert(ret == althrd_success); -} - -void ALCbackend_unlock(ALCbackend *self) -{ - int ret = almtx_unlock(&self->mMutex); - assert(ret == althrd_success); -} - - -/* Base ALCbackendFactory method implementations. */ -void ALCbackendFactory_deinit(ALCbackendFactory* UNUSED(self)) -{ -} diff --git a/Alc/backends/base.cpp b/Alc/backends/base.cpp new file mode 100644 index 00000000..8173f554 --- /dev/null +++ b/Alc/backends/base.cpp @@ -0,0 +1,79 @@ + +#include "config.h" + +#include + +#include "alMain.h" +#include "alu.h" + +#include "backends/base.h" + + +/* Base ALCbackend method implementations. */ +void ALCbackend_Construct(ALCbackend *self, ALCdevice *device) +{ + int ret = almtx_init(&self->mMutex, almtx_recursive); + assert(ret == althrd_success); + self->mDevice = device; +} + +void ALCbackend_Destruct(ALCbackend *self) +{ + almtx_destroy(&self->mMutex); +} + +ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self)) +{ + return ALC_FALSE; +} + +ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples)) +{ + return ALC_INVALID_DEVICE; +} + +ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self)) +{ + return 0; +} + +ClockLatency ALCbackend_getClockLatency(ALCbackend *self) +{ + ALCdevice *device = self->mDevice; + ALuint refcount; + ClockLatency ret; + + 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); + + return ret; +} + +void ALCbackend_lock(ALCbackend *self) +{ + int ret = almtx_lock(&self->mMutex); + assert(ret == althrd_success); +} + +void ALCbackend_unlock(ALCbackend *self) +{ + int ret = almtx_unlock(&self->mMutex); + assert(ret == althrd_success); +} + + +/* Base ALCbackendFactory method implementations. */ +void ALCbackendFactory_deinit(ALCbackendFactory* UNUSED(self)) +{ +} -- cgit v1.2.3