1 #ifndef GAUDIKERNEL_WATCHDOGTHREAD_H_ 2 #define GAUDIKERNEL_WATCHDOGTHREAD_H_ 6 #include <boost/date_time/posix_time/posix_time_types.hpp> 7 #include <boost/thread/thread_time.hpp> 8 #include <boost/thread/mutex.hpp> 14 namespace boost {
class thread; }
31 WatchdogThread(boost::posix_time::time_duration timeout,
bool autostart =
false);
45 boost::mutex::scoped_lock lock(m_lastPingMutex);
46 m_lastPing = boost::get_system_time();
51 inline void setTimeout(boost::posix_time::time_duration timeout) {
56 inline boost::posix_time::time_duration
getTimeout()
const {
62 boost::mutex::scoped_lock lock(m_lastPingMutex);
71 virtual void onPing();
74 virtual void onStart();
77 virtual void onStop();
boost::posix_time::time_duration getTimeout() const
Get the current time-out value.
The namespace threadpool contains a thread pool and related utility classes.
boost::system_time m_lastPing
When the last ping was received.
void setTimeout(boost::posix_time::time_duration timeout)
Change the duration of the time-out.
boost::posix_time::time_duration m_timeout
Number of seconds allowed between pings.
void ping()
Function to call to notify the watchdog thread that we are still alive.
bool m_running
Flag to mark the thread as running/stopped (avoid possible race conditions).
Simple class for asynchronous check of time-out.
boost::mutex m_lastPingMutex
Mutex for the access to the m_lastPing data member.
std::unique_ptr< boost::thread > m_thread
Pointer to the running thread;.
boost::system_time getLastPing() const
Get the time of latest ping.