CARMA C++
|
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world. More...
#include <carma/util/PthreadMutex.h>
Public Member Functions | |
const ::pthread_mutex_t & | InternalPthreadMutex () const |
Obtain a reference to the internal ::pthread_mutex_t. More... | |
::pthread_mutex_t & | InternalPthreadMutex () |
Obtain a reference to the internal ::pthread_mutex_t. More... | |
void | Lock () |
Obtain a lock on the instance for the caller's thread. More... | |
PthreadMutex () | |
Construct a mutex with the CARMA defaults. More... | |
PthreadMutex (int type) | |
Construct a mutex with the given type. More... | |
PthreadMutex (const PthreadMutexAttr &attr) | |
Construct a mutex with the given attributes. More... | |
PthreadMutex (const ::pthread_mutexattr_t &attr) | |
Construct a mutex with the given attributes. More... | |
bool | TryLock () |
Obtain a lock on the instance for the caller's thread and return true if it is possible to do so immediately without blocking and return false if obtaining a lock for the caller's thread would require blocking. More... | |
void | Unlock () |
Release a lock that is held on the instance by the caller's thread. More... | |
int | UnlockNoThrow () |
virtual | ~PthreadMutex () |
Destruct a mutex. More... | |
A simple wrapper class that makes use of ::pthread_mutex_t easier in a C++ world.
If you have no idea what a mutex is then here is the general idea: A mutex is an token/object that only one thread can being holding a lock on at a time. It is used to serialize manipulation/access to some shared resource from multiple threads. Hence, methods of PthreadMutex are safe to call concurrently on a single instance. They wouldn't be terribly useful if this wasn't the case.
Definition at line 41 of file PthreadMutex.h.
|
explicit |
Construct a mutex with the CARMA defaults.
Any internal errors will throw an exception.
|
explicit |
Construct a mutex with the given type.
Any internal errors will throw an exception.
|
explicit |
Construct a mutex with the given attributes.
Any internal errors will throw an exception.
|
explicit |
Construct a mutex with the given attributes.
Any internal errors will throw an exception.
|
virtual |
Destruct a mutex.
No exceptions will be thrown and hence internal errors will be ignored as far as clients are concerned (though they may be logged).
const ::pthread_mutex_t & carma::util::PthreadMutex::InternalPthreadMutex | ( | ) | const |
Obtain a reference to the internal ::pthread_mutex_t.
Definition at line 261 of file PthreadMutex.h.
pthread_mutex_t & carma::util::PthreadMutex::InternalPthreadMutex | ( | ) |
Obtain a reference to the internal ::pthread_mutex_t.
Definition at line 268 of file PthreadMutex.h.
void carma::util::PthreadMutex::Lock | ( | ) |
Obtain a lock on the instance for the caller's thread.
May possibly block or deadlock for an indeterminate amount of time along the way. Detected errors will throw an exception. The behavior if a lock on the instance is already held by the caller's thread at the time of the call is defined (or undefined) by POSIX according to the type of mutex that was constructed.
Definition at line 233 of file PthreadMutex.h.
bool carma::util::PthreadMutex::TryLock | ( | ) |
Obtain a lock on the instance for the caller's thread and return true
if it is possible to do so immediately without blocking and return false
if obtaining a lock for the caller's thread would require blocking.
Detected errors will throw an exception. The behavior is undefined if a lock on the instance is already held by the caller's thread at the time of the call.
true
if a lock was obtained and false
if it was not.true
was returned, a lock is not held on the instance by the caller's thread and false
was returned, or an exception was thrown (in which case a lock is not held on the on the instance by the caller's thread if it was not held by the caller's thread at the time of the call). Definition at line 240 of file PthreadMutex.h.
void carma::util::PthreadMutex::Unlock | ( | ) |
Release a lock that is held on the instance by the caller's thread.
Detected errors will throw an exception. The behavior is undefined if a lock is not held on the instance by the caller's thread at the time of the call.
Definition at line 247 of file PthreadMutex.h.