From d4f64b9e29319f56f2ecab1291918a52ec8336f1 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 15 Nov 2018 03:49:59 -0800 Subject: Use a C++ mutex with the device backend base --- Alc/backends/base.cpp | 21 +++++++++++++-------- Alc/backends/base.h | 14 +++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'Alc') diff --git a/Alc/backends/base.cpp b/Alc/backends/base.cpp index 4a20518d..340ca7ac 100644 --- a/Alc/backends/base.cpp +++ b/Alc/backends/base.cpp @@ -26,14 +26,11 @@ 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) +void ALCbackend_Destruct(ALCbackend* UNUSED(self)) { - almtx_destroy(&self->mMutex); } ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self)) @@ -76,14 +73,22 @@ ClockLatency ALCbackend_getClockLatency(ALCbackend *self) void ALCbackend_lock(ALCbackend *self) { - int ret = almtx_lock(&self->mMutex); - assert(ret == althrd_success); + try { + self->mMutex.lock(); + } + catch(...) { + std::terminate(); + } } void ALCbackend_unlock(ALCbackend *self) { - int ret = almtx_unlock(&self->mMutex); - assert(ret == althrd_success); + try { + self->mMutex.unlock(); + } + catch(...) { + std::terminate(); + } } diff --git a/Alc/backends/base.h b/Alc/backends/base.h index 75950344..f8b5f346 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -2,18 +2,16 @@ #define AL_BACKENDS_BASE_H #include "alMain.h" -#include "threads.h" #include "alstring.h" - #ifdef __cplusplus -extern "C" { -#endif -typedef struct ClockLatency { +#include + +struct ClockLatency { ALint64 ClockTime; ALint64 Latency; -} ClockLatency; +}; /* Helper to get the current clock time from the device's ClockBase, and * SamplesDone converted from the sample rate. @@ -29,8 +27,6 @@ void ALCdevice_Unlock(ALCdevice *device); ClockLatency GetClockLatency(ALCdevice *device); -#ifdef __cplusplus -} /* extern "C" */ struct ALCbackendVtable; @@ -39,7 +35,7 @@ struct ALCbackend { ALCdevice *mDevice; - almtx_t mMutex; + std::recursive_mutex mMutex; }; void ALCbackend_Construct(ALCbackend *self, ALCdevice *device); -- cgit v1.2.3