From f9e969a3391e1c0622e35ceaf5dc541b7f149c5d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 20 Nov 2018 10:55:57 -0800 Subject: [PATCH] Use a standard mutex for the event callback lock --- Alc/alc.cpp | 2 -- Alc/alcontext.h | 4 +++- OpenAL32/alError.cpp | 2 +- OpenAL32/alState.cpp | 4 ++-- OpenAL32/event.cpp | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 00148246..65e77b0d 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2539,7 +2539,6 @@ static ALvoid InitContext(ALCcontext *Context) Context->SpeedOfSound = SPEEDOFSOUNDMETRESPERSEC; Context->MetersPerUnit = AL_DEFAULT_METERS_PER_UNIT; alsem_init(&Context->EventSem, 0); - almtx_init(&Context->EventCbLock, almtx_plain); Context->ExtensionList = alExtList; @@ -2650,7 +2649,6 @@ ALCcontext_struct::~ALCcontext_struct() } TRACE("Freed " SZFMT " listener property object%s\n", count, (count==1)?"":"s"); - almtx_destroy(&EventCbLock); alsem_destroy(&EventSem); ll_ringbuffer_free(AsyncEvents); diff --git a/Alc/alcontext.h b/Alc/alcontext.h index ce715bc2..4a056597 100644 --- a/Alc/alcontext.h +++ b/Alc/alcontext.h @@ -1,6 +1,8 @@ #ifndef ALCONTEXT_H #define ALCONTEXT_H +#include +#include #include #include @@ -102,7 +104,7 @@ struct ALCcontext_struct { alsem_t EventSem; ll_ringbuffer *AsyncEvents{nullptr}; ATOMIC(ALbitfieldSOFT) EnabledEvts{0u}; - almtx_t EventCbLock; + std::mutex EventCbLock; ALEVENTPROCSOFT EventCb{}; void *EventParam{nullptr}; diff --git a/OpenAL32/alError.cpp b/OpenAL32/alError.cpp index 16c89273..39c666d2 100644 --- a/OpenAL32/alError.cpp +++ b/OpenAL32/alError.cpp @@ -73,7 +73,7 @@ void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) context->LastError.compare_exchange_strong(curerr, errorCode); if((context->EnabledEvts.load(std::memory_order_relaxed)&EventType_Error)) { - std::lock_guard _{context->EventCbLock}; + std::lock_guard _{context->EventCbLock}; ALbitfieldSOFT enabledevts{context->EnabledEvts.load(std::memory_order_relaxed)}; if((enabledevts&EventType_Error) && context->EventCb) (*context->EventCb)(AL_EVENT_TYPE_ERROR_SOFT, 0, errorCode, msglen, msg, diff --git a/OpenAL32/alState.cpp b/OpenAL32/alState.cpp index 2901baa2..95a4fd92 100644 --- a/OpenAL32/alState.cpp +++ b/OpenAL32/alState.cpp @@ -664,8 +664,8 @@ AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value) static constexpr ALCchar msg[] = "alDopplerVelocity is deprecated in AL1.1, use alSpeedOfSound"; const ALsizei msglen = (ALsizei)strlen(msg); - std::lock_guard _{context->EventCbLock}; - ALbitfieldSOFT enabledevts{ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed)}; + std::lock_guard _{context->EventCbLock}; + ALbitfieldSOFT enabledevts{context->EnabledEvts.load(std::memory_order_relaxed)}; if((enabledevts&EventType_Deprecated) && context->EventCb) (*context->EventCb)(AL_EVENT_TYPE_DEPRECATED_SOFT, 0, 0, msglen, msg, context->EventParam); diff --git a/OpenAL32/event.cpp b/OpenAL32/event.cpp index d6fa01fb..a2c98928 100644 --- a/OpenAL32/event.cpp +++ b/OpenAL32/event.cpp @@ -27,7 +27,7 @@ static int EventThread(ALCcontext *context) continue; } - std::lock_guard _{context->EventCbLock}; + std::lock_guard _{context->EventCbLock}; do { quitnow = evt.EnumType == EventType_KillThread; if(UNLIKELY(quitnow)) break; @@ -126,7 +126,7 @@ AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, A /* Wait to ensure the event handler sees the changed flags before * returning. */ - std::lock_guard{context->EventCbLock}; + std::lock_guard{context->EventCbLock}; } } @@ -136,7 +136,7 @@ AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *user if(UNLIKELY(!context)) return; std::lock_guard _{context->PropLock}; - std::lock_guard __{context->EventCbLock}; + std::lock_guard __{context->EventCbLock}; context->EventCb = callback; context->EventParam = userParam; }