2023-09-29 17:38:13 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
#include <condition_variable>
|
|
|
|
|
|
|
|
class CWatchdog {
|
|
|
|
public:
|
|
|
|
// must be called from the main thread
|
|
|
|
CWatchdog();
|
2023-09-29 18:33:26 +02:00
|
|
|
~CWatchdog();
|
2023-09-29 17:38:13 +02:00
|
|
|
|
|
|
|
void startWatching();
|
|
|
|
void endWatching();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::chrono::high_resolution_clock::time_point m_tTriggered;
|
|
|
|
|
|
|
|
pthread_t m_iMainThreadPID = 0;
|
|
|
|
|
|
|
|
bool m_bWatching = false;
|
|
|
|
bool m_bWillWatch = false;
|
|
|
|
|
|
|
|
std::unique_ptr<std::thread> m_pWatchdog;
|
|
|
|
std::mutex m_mWatchdogMutex;
|
2023-09-29 21:05:43 +02:00
|
|
|
bool m_bNotified = false;
|
|
|
|
bool m_bExitThread = false;
|
2023-09-29 17:38:13 +02:00
|
|
|
std::condition_variable m_cvWatchdogCondition;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline std::unique_ptr<CWatchdog> g_pWatchdog;
|