CARMA C++
ScopedPthreadMutexLock.h
1 #ifndef CARMA_UTIL_SCOPED_PTHREAD_MUTEX_LOCK_H
2 #define CARMA_UTIL_SCOPED_PTHREAD_MUTEX_LOCK_H
3 
4 
5 #include "carma/util/PthreadMutex.h"
6 #include "carma/util/posixErrors.h"
7 
8 
9 namespace carma {
10 namespace util {
11 
12 
30 
32  public:
33 
39 
40  explicit ScopedPthreadMutexLock( PthreadMutex & mutex );
41 
42 
45 
46  /* virtual */ ~ScopedPthreadMutexLock( );
47 
48  private:
49  // no copying
51  ScopedPthreadMutexLock & operator=( const ScopedPthreadMutexLock & );
52 
53  PthreadMutex & mutex_;
54 };
55 
56 
57 } // namespace util
58 } // namespace carma
59 
60 
61 // ******* Below here is simply implementation *******
62 
63 inline
65 mutex_( m )
66 {
67  mutex_.Lock( );
68 }
69 
70 
71 inline
73 try {
74  logIfPosixError( mutex_.UnlockNoThrow( ) );
75 } catch ( ... ) {
76  // just stifle any exceptions
77 
78  return;
79 }
80 
81 
82 #endif
ScopedPthreadMutexLock(PthreadMutex &mutex)
Obtains a lock on the given mutex for the caller's thread (possibly waiting an indeterminate amount o...
void Lock()
Obtain a lock on the instance for the caller's thread.
Definition: PthreadMutex.h:233
~ScopedPthreadMutexLock()
Releases the lock on the mutex (that was given to the constructor) held by the caller's thread...
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
Definition: PthreadMutex.h:41