internal: add a watchdog
a watchdog will abort processing a signal if a timeout specified via debug:watchdog_timeout is reached.
This commit is contained in:
parent
3f09b14381
commit
9cc614d096
6 changed files with 99 additions and 1 deletions
30
src/helpers/Watchdog.hpp
Normal file
30
src/helpers/Watchdog.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
|
||||
class CWatchdog {
|
||||
public:
|
||||
// must be called from the main thread
|
||||
CWatchdog();
|
||||
|
||||
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;
|
||||
bool m_bNotified = false;
|
||||
std::condition_variable m_cvWatchdogCondition;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CWatchdog> g_pWatchdog;
|
||||
Loading…
Add table
Add a link
Reference in a new issue