CARMA C++
carma::util::PthreadRWLock Class Reference

A simple wrapper class that makes use of ::pthread_rwlock_t easier in a C++ world. More...

#include <carma/util/PthreadRWLock.h>

Public Member Functions

void ExclusiveLock ()
 Obtain an exclusive lock on the instance for the caller's thread. More...
 
void ExclusiveUnlock ()
 Release an exclusive lock on the instance for the caller's thread. More...
 
const ::pthread_rwlock_t & InternalPthreadRWLock () const
 Obtain a reference to the internal ::pthread_rwlock_t. More...
 
::pthread_rwlock_t & InternalPthreadRWLock ()
 Obtain a reference to the internal ::pthread_rwlock_t. More...
 
 PthreadRWLock ()
 Construct a read/write lock with the CARMA defaults. More...
 
 PthreadRWLock (const PthreadRWLockAttr &attr)
 Construct a read/write lock with the given attributes. More...
 
 PthreadRWLock (const ::pthread_rwlockattr_t &attr)
 Construct a read/write lock with the given attributes. More...
 
void SharedLock ()
 Obtain an shared lock on the instance for the caller's thread. More...
 
void SharedUnlock ()
 Release a shared lock on the instance for the caller's thread. More...
 
bool TryExclusiveLock ()
 Try to obtain an exclusive lock on the instance for the caller's thread. More...
 
bool TrySharedLock ()
 Try to obtain a shared lock on the instance for the caller's thread. More...
 
virtual ~PthreadRWLock ()
 Destruct a read/write lock. More...
 

Detailed Description

A simple wrapper class that makes use of ::pthread_rwlock_t easier in a C++ world.

If you have no idea what a read/write lock is then here is the general idea: It is used to serialize manipulation/access to some shared resource from multiple threads. Hence, methods of PthreadRWLock are safe to call concurrently on a single instance. They wouldn't be terribly useful if this wasn't the case.

Definition at line 46 of file PthreadRWLock.h.

Constructor & Destructor Documentation

carma::util::PthreadRWLock::PthreadRWLock ( )
explicit

Construct a read/write lock with the CARMA defaults.

Any internal errors will throw an exception.

Postcondition
No locks are held on the instance by any thread.
carma::util::PthreadRWLock::PthreadRWLock ( const PthreadRWLockAttr attr)
explicit

Construct a read/write lock with the given attributes.

Any internal errors will throw an exception.

Postcondition
No locks are held on the instance by any thread.
carma::util::PthreadRWLock::PthreadRWLock ( const ::pthread_rwlockattr_t &  attr)
explicit

Construct a read/write lock with the given attributes.

Any internal errors will throw an exception.

Postcondition
No locks are held on the instance by any thread.
virtual carma::util::PthreadRWLock::~PthreadRWLock ( )
virtual

Destruct a read/write lock.

No exceptions will be thrown and hence internal errors will be ignored as far as clients are concerned (though they may be logged).

Precondition
No locks are held on the instance by any thread.

Member Function Documentation

void carma::util::PthreadRWLock::ExclusiveLock ( )

Obtain an exclusive lock on the instance for the caller's thread.

Definition at line 241 of file PthreadRWLock.h.

void carma::util::PthreadRWLock::ExclusiveUnlock ( )

Release an exclusive lock on the instance for the caller's thread.

Definition at line 255 of file PthreadRWLock.h.

const ::pthread_rwlock_t & carma::util::PthreadRWLock::InternalPthreadRWLock ( ) const

Obtain a reference to the internal ::pthread_rwlock_t.

Warning
Use this with care. Certainly do not go off and call something like ::pthread_rwlock_destroy on the return value. If you don't know what you are doing with a POSIX read/write lock then think twice before using this method.
Returns
a reference to the internal ::pthread_rwlock_t

Definition at line 283 of file PthreadRWLock.h.

pthread_rwlock_t & carma::util::PthreadRWLock::InternalPthreadRWLock ( )

Obtain a reference to the internal ::pthread_rwlock_t.

Warning
Use this with care. Certainly do not go off and call something like ::pthread_rwlock_destroy on the return value. If you don't know what you are doing with a POSIX read/write lock then think twice before using this method.
Returns
a reference to the internal ::pthread_rwlock_t

Definition at line 290 of file PthreadRWLock.h.

void carma::util::PthreadRWLock::SharedLock ( )

Obtain an shared lock on the instance for the caller's thread.

Definition at line 262 of file PthreadRWLock.h.

void carma::util::PthreadRWLock::SharedUnlock ( )

Release a shared lock on the instance for the caller's thread.

Definition at line 276 of file PthreadRWLock.h.

bool carma::util::PthreadRWLock::TryExclusiveLock ( )

Try to obtain an exclusive lock on the instance for the caller's thread.

Definition at line 248 of file PthreadRWLock.h.

bool carma::util::PthreadRWLock::TrySharedLock ( )

Try to obtain a shared lock on the instance for the caller's thread.

Definition at line 269 of file PthreadRWLock.h.


The documentation for this class was generated from the following file: