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

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

#include <carma/util/ScopedExclusiveLock.h>

Public Member Functions

 ScopedExclusiveLock (L &l)
 Obtains an exclusive lock on the given lock for the caller's thread (possibly waiting an indeterminate amount of time along the way). More...
 
 ~ScopedExclusiveLock ()
 Releases the exclusive 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::ScopedExclusiveLock< 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
* exclusiveLock( l );
* exclusiveUnlock( l );
*
are valid and will exclusive lock and exclusive unlock a lock object if l is of type L &. In particular, to use the types ScopedExclusiveLock< PthreadRWLock > and/or ScopedExclusiveLock< 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;
*
* void
* updateSharedValue( const long long newValue ) {
* ScopedExclusiveLock< LockType > lock( gSharedValueGuard );
*
* gSharedValue = newValue;
* }
*

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

Definition at line 45 of file ScopedExclusiveLock.h.

Constructor & Destructor Documentation

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

Obtains an exclusive 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 exclusive lock on

Definition at line 79 of file ScopedExclusiveLock.h.

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

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

Definition at line 87 of file ScopedExclusiveLock.h.


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