CARMA C++
Sleeper.h
1 #ifndef CARMA_UTIL_SLEEPER_H
2 #define CARMA_UTIL_SLEEPER_H
3 
4 #include <sys/time.h>
5 
6 #include "carma/util/PthreadMutex.h"
7 #include "carma/util/PthreadCond.h"
8 
9 
10 namespace carma {
11 namespace util {
12 
13 
23 class Sleeper {
24  public:
25  explicit Sleeper( );
26 
27  virtual ~Sleeper( );
28 
29  void waitUntilAbsTime( const struct ::timespec & absTime );
30  void waitUntilAbsTime( const struct ::timeval & absTime );
31 
32  void waitForWholeSecDuration( const int duration );
33 
40 
41  private:
42  void internalWaitUntilAbsTime( const struct ::timespec & absTime );
43 
44  PthreadCond cond_;
45  PthreadMutex mutex_;
46  bool interruptRequested_;
47 };
48 
49 
50 } // namespace util
51 } // namespace carma
52 
53 #endif
Abstract base class for PthreadCond::TimedWait based sleeping with quit/interuption support...
Definition: Sleeper.h:23
A simple wrapper class that makes use of ::pthread_cond_t easier in a C++ world.
Definition: PthreadCond.h:43
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41
void interruptPresentOrNextWait()
Interrupt the wait that is presently occurring on this instance or if no such wait is presently occur...