CARMA C++
PthreadCond.h
1 #ifndef CARMA_UTIL_PTHREAD_COND_H
2 #define CARMA_UTIL_PTHREAD_COND_H
3 
4 #include <pthread.h>
5 
6 #include "carma/util/PthreadMutex.h"
7 
8 namespace carma {
9 namespace util {
10 
11 
12 void broadcastCond( ::pthread_cond_t & c );
13 
14 
15 void signalCond( ::pthread_cond_t & c );
16 
17 
18 void waitCond( ::pthread_cond_t & c,
19  ::pthread_mutex_t & m );
20 
21 void waitCond( ::pthread_cond_t & c,
22  PthreadMutex & m );
23 
24 
25 bool timedWaitCond( ::pthread_cond_t & c,
26  ::pthread_mutex_t & m,
27  const struct ::timespec & abstime );
28 
29 bool timedWaitCond( ::pthread_cond_t & c,
30  PthreadMutex & m,
31  const struct ::timespec & abstime );
32 
33 
34 class PthreadCondAttr;
35 
36 
42 
43 class PthreadCond {
44  public:
48  explicit PthreadCond( );
49 
50 
54  explicit PthreadCond( const PthreadCondAttr & attr );
55 
56 
60  explicit PthreadCond( const ::pthread_condattr_t & attr );
61 
62 
63  virtual ~PthreadCond( );
64 
65 
81  void Broadcast( );
82 
83 
100  void Signal( );
101 
102 
110  void Wait( ::pthread_mutex_t & m );
111 
119  void Wait( PthreadMutex & m );
120 
121 
132  bool TimedWait( ::pthread_mutex_t & m,
133  const struct ::timespec & abstime );
134 
145  bool TimedWait( PthreadMutex & m,
146  const struct ::timespec & abstime );
147 
148 
158  const ::pthread_cond_t & InternalPthreadCond( ) const;
159 
160 
170  ::pthread_cond_t & InternalPthreadCond( );
171 
172 
173  private:
174  // no copying
175  PthreadCond( const PthreadCond & rhs );
176  PthreadCond & operator=( const PthreadCond & rhs );
177 
178  ::pthread_cond_t cond_;
179 };
180 
181 
182 } // namespace carma::util
183 } // namespace carma
184 
185 
186 inline void
188 {
189  Wait( m.InternalPthreadMutex() );
190 }
191 
192 
193 inline bool
195  const struct ::timespec & abstime )
196 {
197  return TimedWait( m.InternalPthreadMutex(), abstime );
198 }
199 
200 
201 inline const ::pthread_cond_t &
203 {
204  return cond_;
205 }
206 
207 
208 inline ::pthread_cond_t &
210 {
211  return cond_;
212 }
213 
214 
215 inline void
216 carma::util::waitCond( ::pthread_cond_t & c,
217  PthreadMutex & m )
218 {
219  waitCond( c, m.InternalPthreadMutex() );
220 }
221 
222 
223 inline bool
224 carma::util::timedWaitCond( ::pthread_cond_t & c,
225  PthreadMutex & m,
226  const struct ::timespec & abstime )
227 {
228  return timedWaitCond( c, m.InternalPthreadMutex(), abstime );
229 }
230 
231 
232 #endif
const ::pthread_cond_t & InternalPthreadCond() const
Obtain a reference to the internal ::pthread_cond_t.
Definition: PthreadCond.h:202
void Signal()
Wake one of any waiters.
A simple wrapper class that makes use of ::pthread_cond_t easier in a C++ world.
Definition: PthreadCond.h:43
void Broadcast()
Wake any waiters.
PthreadCond()
Default construct a cond with the CARMA defaults.
bool TimedWait(::pthread_mutex_t &m, const struct::timespec &abstime)
Wait until waken or timed out.
void Wait(::pthread_mutex_t &m)
Wait until waken.
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41
A simple wrapper class that makes use of ::pthread_condattr_t easier in a C++ world.
const ::pthread_mutex_t & InternalPthreadMutex() const
Obtain a reference to the internal ::pthread_mutex_t.
Definition: PthreadMutex.h:261