10 #include <boost/thread/thread.hpp> 13 : m_timeout(
std::move( timeout ) ), m_running( false )
16 if ( autostart )
start();
57 boost::system_time nextCheck = lastPing +
getTimeout();
65 boost::thread::sleep( nextCheck );
70 nextCheck = boost::get_system_time() +
getTimeout();
79 catch ( boost::thread_interrupted& ) {
boost::posix_time::time_duration getTimeout() const
Get the current time-out value.
void start()
Start the watchdog thread.
virtual void onStop()
User implemented function that will be called when stopping.
GAUDI_API void NanoSleep(long long nsec)
Small variation on the sleep function for nanoseconds sleep.
void ping()
Function to call to notify the watchdog thread that we are still alive.
virtual ~WatchdogThread()
Destructor.
bool m_running
Flag to mark the thread as running/stopped (avoid possible race conditions).
virtual void onPing()
User implemented function that will be called when ping is called.
void stop()
Signal the watchdog thread to stop and wait for it.
virtual void action()
User implemented function that will be called if the time-out is reached.
WatchdogThread(boost::posix_time::time_duration timeout, bool autostart=false)
Constructor.
void i_run()
Core function of the secondary thread.
std::unique_ptr< boost::thread > m_thread
Pointer to the running thread;.
boost::system_time getLastPing() const
Get the time of latest ping.
virtual void onStart()
User implemented function that will be called when starting.