From f2a0df87916de7b9fa8b65a52814c9a09fc6bee9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Apr 2023 14:36:56 -0700 Subject: Unlock the debug lock when calling the callback There's no full guarantee about calling AL functions in a debug callback, due to a risk of deadlocks from an AL call that tries to take a lock that's already held at the time the callback is invoked, but this helps more work. --- alc/context.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/alc/context.cpp b/alc/context.cpp index 6553f322..4e5a3ab6 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -342,7 +342,7 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; }; - std::lock_guard _{mDebugCbLock}; + std::unique_lock debuglock{mDebugCbLock}; if(!mDebugEnabled.load()) UNLIKELY return; @@ -355,8 +355,13 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, return; if(mDebugCb) - mDebugCb(get_source_enum(source), get_type_enum(type), id, get_severity_enum(severity), - length, message, mDebugParam); + { + auto callback = mDebugCb; + auto param = mDebugParam; + debuglock.unlock(); + callback(get_source_enum(source), get_type_enum(type), id, get_severity_enum(severity), + length, message, param); + } else { /* TODO: Store in a log. */ -- cgit v1.2.3