1 #ifndef CARMA_UTIL_PTHREAD_MUTEX_H
2 #define CARMA_UTIL_PTHREAD_MUTEX_H
7 #include "carma/util/posixErrors.h"
14 class PthreadMutexAttr;
18 void lockMutex( ::pthread_mutex_t & );
19 void lockMutex( PthreadMutex & );
21 bool tryLockMutex( ::pthread_mutex_t & );
22 bool tryLockMutex( PthreadMutex & );
24 void unlockMutex( ::pthread_mutex_t & );
25 void unlockMutex( PthreadMutex & );
27 int unlockMutexNoThrow( ::pthread_mutex_t & );
28 int unlockMutexNoThrow( PthreadMutex & );
77 explicit PthreadMutex( const ::pthread_mutexattr_t & attr );
145 int UnlockNoThrow( );
177 ::pthread_mutex_t mutex_;
186 carma::util::lockMutex( ::pthread_mutex_t & m )
188 failIfPosixError( ::pthread_mutex_lock( &m ),
189 "::pthread_mutex_lock error" );
194 carma::util::tryLockMutex( ::pthread_mutex_t & m )
198 const int posixRetVal = ::pthread_mutex_trylock( &m );
200 switch ( posixRetVal ) {
210 throwPosixError( posixRetVal,
"::pthread_mutex_lock error" );
218 carma::util::unlockMutex( ::pthread_mutex_t & m )
220 failIfPosixError( ::pthread_mutex_unlock( &m ),
221 "::pthread_mutex_unlock error" );
226 carma::util::unlockMutexNoThrow( ::pthread_mutex_t & m )
228 return ::pthread_mutex_unlock( &m );
242 return tryLockMutex( mutex_ );
249 unlockMutex( mutex_ );
254 carma::util::PthreadMutex::UnlockNoThrow( )
256 return unlockMutexNoThrow( mutex_ );
260 inline const ::pthread_mutex_t &
267 inline ::pthread_mutex_t &
282 carma::util::tryLockMutex( PthreadMutex & m )
289 carma::util::unlockMutex( PthreadMutex & m )
296 carma::util::unlockMutexNoThrow( PthreadMutex & m )
298 return m.UnlockNoThrow();
PthreadMutex()
Construct a mutex with the CARMA defaults.
virtual ~PthreadMutex()
Destruct a mutex.
bool TryLock()
Obtain a lock on the instance for the caller's thread and return true if it is possible to do so imme...
void Lock()
Obtain a lock on the instance for the caller's thread.
A simple wrapper class that makes use of ::pthread_mutexattr_t easier in a C++ world.
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. ...
const ::pthread_mutex_t & InternalPthreadMutex() const
Obtain a reference to the internal ::pthread_mutex_t.
void Unlock()
Release a lock that is held on the instance by the caller's thread.