Use a C++ mutex with the device backend base

This commit is contained in:
Chris Robinson
2018-11-15 03:49:59 -08:00
parent b7daddb564
commit d4f64b9e29
2 changed files with 18 additions and 17 deletions
+13 -8
View File
@@ -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();
}
}
+5 -9
View File
@@ -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 <mutex>
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);