LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
lsst::ap::ScopedLock< MutexT > Class Template Reference

Grants access to a mutex, enforcing the RAII principle. More...

#include <Mutex.h>

Inheritance diagram for lsst::ap::ScopedLock< MutexT >:

Public Types

typedef MutexT *ScopedLock::* UnspecifiedBool
 

Public Member Functions

 ScopedLock ()
 
 ScopedLock (MutexT &m)
 
 ~ScopedLock ()
 
void acquire (MutexT &m)
 Acquires the given Mutex. More...
 
bool tryAcquire (MutexT &m)
 
void release ()
 
bool isAcquired () const
 
 operator UnspecifiedBool () const
 
bool operator! () const
 

Private Member Functions

::pthread_mutex_t * getPosixMutex ()
 

Private Attributes

MutexT * _mutex
 

Friends

class Condition< MutexT >
 

Detailed Description

template<typename MutexT>
class lsst::ap::ScopedLock< MutexT >

Grants access to a mutex, enforcing the RAII principle.

Definition at line 51 of file Mutex.h.

Member Typedef Documentation

template<typename MutexT>
typedef MutexT* ScopedLock::* lsst::ap::ScopedLock< MutexT >::UnspecifiedBool

Definition at line 192 of file Mutex.h.

Constructor & Destructor Documentation

template<typename MutexT>
lsst::ap::ScopedLock< MutexT >::ScopedLock ( )
inline

Definition at line 137 of file Mutex.h.

137 : _mutex(0) {}
MutexT * _mutex
Definition: Mutex.h:204
template<typename MutexT>
lsst::ap::ScopedLock< MutexT >::ScopedLock ( MutexT &  m)
inlineexplicit

Definition at line 139 of file Mutex.h.

139  : _mutex(&m) {
140  m.acquire();
141  }
MutexT * _mutex
Definition: Mutex.h:204
template<typename MutexT>
lsst::ap::ScopedLock< MutexT >::~ScopedLock ( )
inline

Definition at line 143 of file Mutex.h.

143  {
144  if (_mutex != 0) {
145  _mutex->release();
146  _mutex = 0;
147  }
148  }
MutexT * _mutex
Definition: Mutex.h:204

Member Function Documentation

template<typename MutexT>
void lsst::ap::ScopedLock< MutexT >::acquire ( MutexT &  m)
inline

Acquires the given Mutex.

Definition at line 151 of file Mutex.h.

151  {
152  assert(_mutex == 0);
153  _mutex = &m;
154  m.acquire();
155  }
MutexT * _mutex
Definition: Mutex.h:204
template<typename MutexT>
::pthread_mutex_t* lsst::ap::ScopedLock< MutexT >::getPosixMutex ( )
inlineprivate

Definition at line 206 of file Mutex.h.

206  {
207  return &(_mutex->_mutex);
208  }
MutexT * _mutex
Definition: Mutex.h:204
template<typename MutexT>
bool lsst::ap::ScopedLock< MutexT >::isAcquired ( ) const
inline

Returns true if and only if a Mutex is currently held; that is, if a Mutex was obtained via acquire(Mutex &) or tryAcquire(Mutex &) but not yet released via release().

Definition at line 187 of file Mutex.h.

187  {
188  return _mutex != 0;
189  }
MutexT * _mutex
Definition: Mutex.h:204
template<typename MutexT>
lsst::ap::ScopedLock< MutexT >::operator UnspecifiedBool ( ) const
inline

Definition at line 194 of file Mutex.h.

194  {
195  return _mutex == 0 ? 0 : &ScopedLock::_mutex;
196  }
MutexT * _mutex
Definition: Mutex.h:204
template<typename MutexT>
bool lsst::ap::ScopedLock< MutexT >::operator! ( ) const
inline

Definition at line 198 of file Mutex.h.

198  {
199  return _mutex == 0;
200  }
MutexT * _mutex
Definition: Mutex.h:204
template<typename MutexT>
void lsst::ap::ScopedLock< MutexT >::release ( )
inline

Releases a previously acquired Mutex.

Precondition
A Mutex was previously acquired via acquire(Mutex &) or tryAcquire(Mutex &).

Definition at line 177 of file Mutex.h.

177  {
178  assert(_mutex != 0);
179  _mutex->release();
180  _mutex = 0;
181  }
MutexT * _mutex
Definition: Mutex.h:204
template<typename MutexT>
bool lsst::ap::ScopedLock< MutexT >::tryAcquire ( MutexT &  m)
inline

Attempts to acquire the given Mutex, returning immediately if this is not possible.

Precondition
Any previously acquired Mutex was released
Returns
true if the mutual exclusion lock was acquired, false otherwise.

Definition at line 163 of file Mutex.h.

163  {
164  assert(_mutex == 0);
165  if (m.tryAcquire()) {
166  _mutex = &m;
167  return true;
168  }
169  return false;
170  }
MutexT * _mutex
Definition: Mutex.h:204

Friends And Related Function Documentation

template<typename MutexT>
friend class Condition< MutexT >
friend

Definition at line 210 of file Mutex.h.

Member Data Documentation

template<typename MutexT>
MutexT* lsst::ap::ScopedLock< MutexT >::_mutex
private

Definition at line 204 of file Mutex.h.


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