| The Gaudi Framework v29r1 (5cd95fa2)

- 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/mutex.hpp>
8 #include <boost/thread/thread_time.hpp>
9
10 // for GAUDI_API
11 #include "GaudiKernel/Kernel.h"
12
13 // forward declaration
14 namespace boost
15 {
16 class thread;
17 }
18
28 class GAUDI_API WatchdogThread
29 {
30 public:
32 // @param timeout the time span that can occur between two pings.
33 // @param autostart if set to true, the second thread is started automatically
34 // on construction, otherwise the user have to call start().
35 WatchdogThread( boost::posix_time::time_duration timeout, bool autostart = false );
36
38 // Stop the thread of not done earlier.
39 virtual ~WatchdogThread();
40
42 void start();
43
45 void stop();
46
48 inline void ping()
49 {
50 boost::mutex::scoped_lock lock( m_lastPingMutex );
51 m_lastPing = boost::get_system_time();
52 onPing();
53 }
54
56 inline void setTimeout( boost::posix_time::time_duration timeout ) { m_timeout = timeout; }
57
59 inline boost::posix_time::time_duration getTimeout() const { return m_timeout; }
60
62 inline boost::system_time getLastPing() const
63 {
64 boost::mutex::scoped_lock lock( m_lastPingMutex );
65 return m_lastPing;
66 }
67
68 protected:
70 virtual void action();
71
73 virtual void onPing();
74
76 virtual void onStart();
77
79 virtual void onStop();
80
81 private:
83 boost::posix_time::time_duration m_timeout;
84
86 boost::system_time m_lastPing;
87
89 std::unique_ptr<boost::thread> m_thread;
90
92 bool m_running;
93
95 // Waits for the time-out and if there was not a ping in the mean time, calls
96 // i_action().
97 void i_run();
98
100 mutable boost::mutex m_lastPingMutex;
101 };
102
103 #endif /* WATCHDOGTHREAD_H_ */
Kernel.h
WatchdogThread::getTimeout
boost::posix_time::time_duration getTimeout() const
Get the current time-out value.
Definition: WatchdogThread.h:59
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:86
WatchdogThread::setTimeout
void setTimeout(boost::posix_time::time_duration timeout)
Change the duration of the time-out.
Definition: WatchdogThread.h:56
WatchdogThread::m_timeout
boost::posix_time::time_duration m_timeout
Number of seconds allowed between pings.
Definition: WatchdogThread.h:83
WatchdogThread::ping
void ping()
Function to call to notify the watchdog thread that we are still alive.
Definition: WatchdogThread.h:48
IOTest.start
start
Definition: IOTest.py:99
action
std::function< StatusCode()> action
Definition: AvalancheSchedulerSvc.h:33
WatchdogThread::m_running
bool m_running
Flag to mark the thread as running/stopped (avoid possible race conditions).
Definition: WatchdogThread.h:92
std::unique_ptr< boost::thread >
WatchdogThread
Simple class for asynchronous check of time-out.
Definition: WatchdogThread.h:28
WatchdogThread::m_lastPingMutex
boost::mutex m_lastPingMutex
Mutex for the access to the m_lastPing data member.
Definition: WatchdogThread.h:100
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
WatchdogThread::m_thread
std::unique_ptr< boost::thread > m_thread
Pointer to the running thread;.
Definition: WatchdogThread.h:89
WatchdogThread::getLastPing
boost::system_time getLastPing() const
Get the time of latest ping.
Definition: WatchdogThread.h:62