| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

WatchdogThread.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_WATCHDOGTHREAD_H_
2 #define GAUDIKERNEL_WATCHDOGTHREAD_H_
3
4 #include <memory>
5
6 #include <boost/date_time/posix_time/posix_time_types.hpp>
7 #include <boost/thread/thread_time.hpp>
8 #include <boost/thread/mutex.hpp>
9
10 // for GAUDI_API
11 #include "GaudiKernel/Kernel.h"
12
13 // forward declaration
14 namespace boost { class thread; }
15
25 class GAUDI_API WatchdogThread {
26 public:
28 // @param timeout the time span that can occur between two pings.
29 // @param autostart if set to true, the second thread is started automatically
30 // on construction, otherwise the user have to call start().
31 WatchdogThread(boost::posix_time::time_duration timeout, bool autostart = false);
32
34 // Stop the thread of not done earlier.
35 virtual ~WatchdogThread();
36
38 void start();
39
41 void stop();
42
44 inline void ping() {
45 boost::mutex::scoped_lock lock(m_lastPingMutex);
46 m_lastPing = boost::get_system_time();
47 onPing();
48 }
49
51 inline void setTimeout(boost::posix_time::time_duration timeout) {
52 m_timeout = timeout;
53 }
54
56 inline boost::posix_time::time_duration getTimeout() const {
57 return m_timeout;
58 }
59
61 inline boost::system_time getLastPing() const {
62 boost::mutex::scoped_lock lock(m_lastPingMutex);
63 return m_lastPing;
64 }
65
66 protected:
68 virtual void action();
69
71 virtual void onPing();
72
74 virtual void onStart();
75
77 virtual void onStop();
78
79 private:
81 boost::posix_time::time_duration m_timeout;
82
84 boost::system_time m_lastPing;
85
87 std::unique_ptr<boost::thread> m_thread;
88
90 bool m_running;
91
93 // Waits for the time-out and if there was not a ping in the mean time, calls
94 // i_action().
95 void i_run();
96
98 mutable boost::mutex m_lastPingMutex;
99 };
100
101 #endif /* WATCHDOGTHREAD_H_ */
Kernel.h
WatchdogThread::getTimeout
boost::posix_time::time_duration getTimeout() const
Get the current time-out value.
Definition: WatchdogThread.h:56
boost
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
WatchdogThread::m_lastPing
boost::system_time m_lastPing
When the last ping was received.
Definition: WatchdogThread.h:84
WatchdogThread::setTimeout
void setTimeout(boost::posix_time::time_duration timeout)
Change the duration of the time-out.
Definition: WatchdogThread.h:51
WatchdogThread::m_timeout
boost::posix_time::time_duration m_timeout
Number of seconds allowed between pings.
Definition: WatchdogThread.h:81
WatchdogThread::ping
void ping()
Function to call to notify the watchdog thread that we are still alive.
Definition: WatchdogThread.h:44
IOTest.start
start
Definition: IOTest.py:88
action
std::function< StatusCode()> action
Definition: AvalancheSchedulerSvc.h:31
WatchdogThread::m_running
bool m_running
Flag to mark the thread as running/stopped (avoid possible race conditions).
Definition: WatchdogThread.h:90
std::unique_ptr< boost::thread >
WatchdogThread
Simple class for asynchronous check of time-out.
Definition: WatchdogThread.h:25
WatchdogThread::m_lastPingMutex
boost::mutex m_lastPingMutex
Mutex for the access to the m_lastPing data member.
Definition: WatchdogThread.h:98
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
WatchdogThread::m_thread
std::unique_ptr< boost::thread > m_thread
Pointer to the running thread;.
Definition: WatchdogThread.h:87
WatchdogThread::getLastPing
boost::system_time getLastPing() const
Get the time of latest ping.
Definition: WatchdogThread.h:61