diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | OpenAL32/alError.cpp (renamed from OpenAL32/alError.c) | 29 |
2 files changed, 11 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c73e0d69..bf925917 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -784,7 +784,7 @@ SET(OPENAL_OBJS OpenAL32/Include/alEffect.h OpenAL32/alEffect.c OpenAL32/Include/alError.h - OpenAL32/alError.c + OpenAL32/alError.cpp OpenAL32/alExtension.cpp OpenAL32/Include/alFilter.h OpenAL32/alFilter.c diff --git a/OpenAL32/alError.c b/OpenAL32/alError.cpp index b6208f77..cf56dd71 100644 --- a/OpenAL32/alError.c +++ b/OpenAL32/alError.cpp @@ -36,13 +36,11 @@ ALboolean TrapALError = AL_FALSE; void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) { - ALenum curerr = AL_NO_ERROR; - char message[1024] = { 0 }; - va_list args; - int msglen; + char message[1024]{}; + va_list args; va_start(args, msg); - msglen = vsnprintf(message, sizeof(message), msg, args); + int msglen{snprintf(message, sizeof(message), msg, args)}; va_end(args); if(msglen < 0 || (size_t)msglen >= sizeof(message)) @@ -71,28 +69,24 @@ void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) #endif } + ALenum curerr{AL_NO_ERROR}; ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(&context->LastError, &curerr, errorCode); if((ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed)&EventType_Error)) { - ALbitfieldSOFT enabledevts; - almtx_lock(&context->EventCbLock); - enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed); + std::lock_guard<almtx_t> _{context->EventCbLock}; + ALbitfieldSOFT enabledevts{ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed)}; if((enabledevts&EventType_Error) && context->EventCb) (*context->EventCb)(AL_EVENT_TYPE_ERROR_SOFT, 0, errorCode, msglen, msg, context->EventParam); - almtx_unlock(&context->EventCbLock); } } AL_API ALenum AL_APIENTRY alGetError(void) { - ALCcontext *context; - ALenum errorCode; - - context = GetContextRef(); - if(!context) + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) { - const ALenum deferror = AL_INVALID_OPERATION; + constexpr ALenum deferror{AL_INVALID_OPERATION}; WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror); if(TrapALError) { @@ -106,8 +100,5 @@ AL_API ALenum AL_APIENTRY alGetError(void) return deferror; } - errorCode = ATOMIC_EXCHANGE_SEQ(&context->LastError, AL_NO_ERROR); - - ALCcontext_DecRef(context); - return errorCode; + return ATOMIC_EXCHANGE_SEQ(&context->LastError, AL_NO_ERROR); } |