33 while (
itsRunning.load() ==
false) std::this_thread::sleep_for(std::chrono::milliseconds(5));
48{ itsReset.store(
true); }
53 itsRunning.store(
true);
54 if (timeout <= 0.0F)
return;
55 auto const dur = std::chrono::microseconds(
long(timeout * 1.0e6));
57 while (itsRunning.load())
60 itsReset.store(
false);
61 std::this_thread::sleep_for(dur);
64 if (itsReset.load() ==
false)
66 LERROR(
"Watchdog timed out -- KILLING PROCESS");
#define JEVOIS_WAIT_GET_FUTURE(f)
Wait for a future to become ready for 5 seconds, get(), warn and ignore exception,...
std::atomic< bool > itsRunning
~Watchdog()
Virtual destructor for safe inheritance.
std::future< void > itsRunFut
Watchdog(double timeout)
Constructor.
void reset()
Reset our internal timer. If this does not happen at least every timeout seconds, process is killed.
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
std::string system(std::string const &cmd, bool errtoo=true)
Execute a command and grab stdout output to a string.
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async_little(Function &&f, Args &&... args)
Async execution using a thread pool.