CPN
Computational Process Networks
Public Member Functions | Private Attributes | List of all members
AutoLock< Lockable > Class Template Reference

#include <AutoLock.h>

+ Collaboration diagram for AutoLock< Lockable >:

Public Member Functions

 AutoLock (Lockable &mutex_)
 
 AutoLock (Lockable &mutex_, bool lock)
 
 ~AutoLock ()
 
void Unlock ()
 
void Lock ()
 

Private Attributes

Lockable & mutex
 
int count
 

Detailed Description

template<class Lockable>
class AutoLock< Lockable >

An automatic lock that ensures the lock is left in the state at construction when destroyed.

Definition at line 35 of file AutoLock.h.

Constructor & Destructor Documentation

template<class Lockable>
AutoLock< Lockable >::AutoLock ( Lockable &  mutex_)
inline

Create a new AutoLock and lock the mutex.

Parameters
mutex_the mutex

Definition at line 41 of file AutoLock.h.

References AutoLock< Lockable >::Lock().

41  : mutex(mutex_), count(0) {
42  Lock();
43  }
void Lock()
Definition: AutoLock.h:69
int count
Definition: AutoLock.h:76
Lockable & mutex
Definition: AutoLock.h:75

+ Here is the call graph for this function:

template<class Lockable>
AutoLock< Lockable >::AutoLock ( Lockable &  mutex_,
bool  lock 
)
inline

Create a new AutoLock and only lock the mutex if lock is true

Parameters
mutex_the mutex
locktrue to lock or false to not

Definition at line 49 of file AutoLock.h.

References AutoLock< Lockable >::Lock().

49  : mutex(mutex_), count(0) {
50  if (lock) { Lock(); }
51  }
void Lock()
Definition: AutoLock.h:69
int count
Definition: AutoLock.h:76
Lockable & mutex
Definition: AutoLock.h:75

+ Here is the call graph for this function:

template<class Lockable>
AutoLock< Lockable >::~AutoLock ( )
inline

Definition at line 53 of file AutoLock.h.

References AutoLock< Lockable >::count, and AutoLock< Lockable >::Unlock().

53  {
54  while (count > 0)
55  Unlock();
56  }
void Unlock()
Definition: AutoLock.h:61
int count
Definition: AutoLock.h:76

+ Here is the call graph for this function:

Member Function Documentation

template<class Lockable>
void AutoLock< Lockable >::Lock ( void  )
inline

Unlock the mutex

Definition at line 69 of file AutoLock.h.

References AutoLock< Lockable >::count, and AutoLock< Lockable >::mutex.

Referenced by AutoLock< Lockable >::AutoLock(), and CPN::Kernel::EntryPoint().

69  {
70  mutex.Lock();
71  ++count;
72  }
int count
Definition: AutoLock.h:76
Lockable & mutex
Definition: AutoLock.h:75

+ Here is the caller graph for this function:

template<class Lockable>
void AutoLock< Lockable >::Unlock ( void  )
inline

Member Data Documentation

template<class Lockable>
int AutoLock< Lockable >::count
private
template<class Lockable>
Lockable& AutoLock< Lockable >::mutex
private

Definition at line 75 of file AutoLock.h.

Referenced by AutoLock< Lockable >::Lock(), and AutoLock< Lockable >::Unlock().


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