summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/Watchdog.cpp13
-rw-r--r--src/helpers/Watchdog.hpp14
2 files changed, 14 insertions, 13 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;
diff --git a/src/helpers/Watchdog.hpp b/src/helpers/Watchdog.hpp
index 7bb499d6..b16cb518 100644
--- a/src/helpers/Watchdog.hpp
+++ b/src/helpers/Watchdog.hpp
@@ -11,21 +11,23 @@ class CWatchdog {
CWatchdog();
~CWatchdog();
- void startWatching();
- void endWatching();
+ void startWatching();
+ void endWatching();
+
+ std::atomic<bool> m_bWatchdogInitialized{false};
private:
std::chrono::high_resolution_clock::time_point m_tTriggered;
pthread_t m_iMainThreadPID = 0;
- bool m_bWatching = false;
- bool m_bWillWatch = false;
+ std::atomic<bool> m_bWatching = false;
+ std::atomic<bool> m_bWillWatch = false;
std::unique_ptr<std::thread> m_pWatchdog;
std::mutex m_mWatchdogMutex;
- bool m_bNotified = false;
- bool m_bExitThread = false;
+ std::atomic<bool> m_bNotified = false;
+ std::atomic<bool> m_bExitThread = false;
std::condition_variable m_cvWatchdogCondition;
};