CARMA C++
carma::util::ScopedSharedLock< L > Class Template Reference

A templated scope class (i.e. More...

#include <carma/util/ScopedSharedLock.h>

Public Member Functions

 ScopedSharedLock (L &l)
 Obtains an shared lock on the given lock for the caller's thread (possibly waiting an indeterminate amount of time along the way). More...
 
 ~ScopedSharedLock ()
 Releases the shared lock on the lock (that was given to the constructor) held by the caller's thread. More...
 

Detailed Description

template<typename L>
class carma::util::ScopedSharedLock< L >

A templated scope class (i.e.

a class that does or manages something for the lifetime of the instance) that makes simple lock management easier in a C++ world.

Note
Please note that use of this template requires that the expressions
* sharedLock( l );
* sharedUnlock( l );
*
are valid and will shared lock and shared unlock a lock object if l is of type L &. In particular, to use the types ScopedSharedLock< PthreadRWLock > and/or ScopedSharedLock< pthread_rwlock_t > you will need to include the file "carma/util/PthreadRWLock.h" to get prototypes for the appropriate functions.

Typical usage would look something like this:

* #include "LockType.h"
*
* static long long gSharedValue;
* static LockType gSharedValueGuard;
*
* long long
* fetchSharedValue( ) {
* long long result;
*
* {
* ScopedSharedLock< LockType > lock( gSharedValueGuard );
*
* result = gSharedValue;
* }
*
* return result;
* }
*

If your locking needs are not so simple then ScopedSharedLockManager< L > might be what you need.

Definition at line 50 of file ScopedSharedLock.h.

Constructor & Destructor Documentation

template<typename L >
carma::util::ScopedSharedLock< L >::ScopedSharedLock ( L &  l)
explicit

Obtains an shared lock on the given lock for the caller's thread (possibly waiting an indeterminate amount of time along the way).

Parameters
lThe lock to to wait for an shared lock on

Definition at line 84 of file ScopedSharedLock.h.

template<typename L >
carma::util::ScopedSharedLock< L >::~ScopedSharedLock ( )

Releases the shared lock on the lock (that was given to the constructor) held by the caller's thread.

Definition at line 93 of file ScopedSharedLock.h.


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