debug: fix data race in Debug::log() (#11931)
* debug: fix data race in Debug::log() The templated Debug::log() had mutex protection but the non-template overload it calls didn't, causing crashes when plugins called log from background threads (like hypr-dynamic-cursors loading cursor themes). Fixed by moving the mutex lock from the template version into the non-template version, so all writes to shared state are protected. Fixes: hyprwm/Hyprland#11929 Fixes: VirtCode/hypr-dynamic-cursors#99 * debug: apply clang-format to Log.cpp Fix formatting to satisfy CI clang-format check. --------- Co-authored-by: Dave Walker <dave@daviey.com>
This commit is contained in:
parent
76d998743a
commit
cfac27251a
2 changed files with 3 additions and 3 deletions
|
|
@ -24,7 +24,9 @@ void Debug::log(eLogLevel level, std::string str) {
|
||||||
if (m_shuttingDown)
|
if (m_shuttingDown)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string coloredStr = str;
|
std::lock_guard<std::mutex> guard(m_logMutex);
|
||||||
|
|
||||||
|
std::string coloredStr = str;
|
||||||
//NOLINTBEGIN
|
//NOLINTBEGIN
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case LOG:
|
case LOG:
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,6 @@ namespace Debug {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
//NOLINTNEXTLINE
|
//NOLINTNEXTLINE
|
||||||
void log(eLogLevel level, std::format_string<Args...> fmt, Args&&... args) {
|
void log(eLogLevel level, std::format_string<Args...> fmt, Args&&... args) {
|
||||||
std::lock_guard<std::mutex> guard(m_logMutex);
|
|
||||||
|
|
||||||
if (level == TRACE && !m_trace)
|
if (level == TRACE && !m_trace)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue