CARMA C++
carma::util::ScopedLock< M > Class Template Reference

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

#include <carma/util/ScopedLock.h>

Public Member Functions

 ScopedLock (M &m)
 Obtains a lock on the given mutex for the caller's thread (possibly waiting an indeterminate amount of time along the way). More...
 
 ~ScopedLock ()
 Releases the lock on the mutex (that was given to the constructor) held by the caller's thread. More...
 

Detailed Description

template<typename M>
class carma::util::ScopedLock< M >

A templated scope class (i.e.

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

Note
Please note that use of this template requires that the expressions
* lockMutex( m );
* unlockMutexNoThrow( m );
*
are valid and will lock and unlock a mutex object if m is of type M &. In particular, to use the types ScopedLock< PthreadMutex > and/or ScopedLock< pthread_mutex_t > you will need to include the file "carma/util/PthreadMutex.h" to get prototypes for the appropriate functions.

Typical usage would look something like this:

* #include "MutexType.h"
*
* static long long gSharedValue;
* static MutexType gSharedValueGuard;
*
* void
* UpdateSharedValue( const long long newValue ) {
* ScopedLock< MutexType > scopeLock( gSharedValueGuard );
*
* gSharedValue = newValue;
* }
*

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

Definition at line 46 of file ScopedLock.h.

Constructor & Destructor Documentation

template<typename M >
carma::util::ScopedLock< M >::ScopedLock ( M &  m)
explicit

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

Parameters
mThe mutex to to wait for a lock on

Definition at line 79 of file ScopedLock.h.

template<typename M >
carma::util::ScopedLock< M >::~ScopedLock ( )

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

Definition at line 88 of file ScopedLock.h.


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