diff options
author | Tom Englund <[email protected]> | 2024-08-12 19:19:03 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-08-12 18:19:03 +0100 |
commit | 3fa6db1e7a7f5596f449ae12d0b45ff364d7f6f1 (patch) | |
tree | fda33f86c4706dd151e4cb17908bee60f4434d0a /src/helpers/Watchdog.cpp | |
parent | d361fcbd85a92f0494c6d8ef0c63aad798df20a7 (diff) | |
download | Hyprland-3fa6db1e7a7f5596f449ae12d0b45ff364d7f6f1.tar.gz Hyprland-3fa6db1e7a7f5596f449ae12d0b45ff364d7f6f1.zip |
core: fix data race and a unsigned int rollover (#7278)
* keybindmgr: avoid uint rollover on mouse keycode
mouse keycode is 0, and the switch case checks for 0 - 8 and rolls over,
just return early if keycode is 0.
* watchdog: avoid data races in watchdog
asan thread sanitizer reported data races in the watchdog from reading
and setting the bool variables make them std::atomic bools. also add a
atomic bool for the main thread to wait for to avoid data race when
reading the config values.
* hyprdebug: change non unicode character to name
asan created false positives and didnt like this bit, so for the sake of
easier debugging rename it to something unicode.
Diffstat (limited to 'src/helpers/Watchdog.cpp')
-rw-r--r-- | src/helpers/Watchdog.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/helpers/Watchdog.cpp b/src/helpers/Watchdog.cpp index b9f654da..c7ff648b 100644 --- a/src/helpers/Watchdog.cpp +++ b/src/helpers/Watchdog.cpp @@ -18,15 +18,14 @@ CWatchdog::CWatchdog() { m_pWatchdog = std::make_unique<std::thread>([this] { static auto PTIMEOUT = CConfigValue<Hyprlang::INT>("debug:watchdog_timeout"); - while (1337) { - std::unique_lock lk(m_mWatchdogMutex); + m_bWatchdogInitialized = true; + while (!m_bExitThread) { + std::unique_lock<std::mutex> lk(m_mWatchdogMutex); if (!m_bWillWatch) - m_cvWatchdogCondition.wait(lk, [this] { return m_bNotified; }); - else { - if (m_cvWatchdogCondition.wait_for(lk, std::chrono::milliseconds((int)(*PTIMEOUT * 1000.0)), [this] { return m_bNotified; }) == false) - pthread_kill(m_iMainThreadPID, SIGUSR1); - } + m_cvWatchdogCondition.wait(lk, [this] { return m_bNotified || m_bExitThread; }); + else if (m_cvWatchdogCondition.wait_for(lk, std::chrono::milliseconds((int)(*PTIMEOUT * 1000.0)), [this] { return m_bNotified || m_bExitThread; }) == false) + pthread_kill(m_iMainThreadPID, SIGUSR1); if (m_bExitThread) break; |