CPN
Computational Process Networks
Public Member Functions | Private Attributes | Friends | List of all members
Sync::ReentrantLock Class Reference

#include <ReentrantLock.h>

+ Collaboration diagram for Sync::ReentrantLock:

Public Member Functions

 ReentrantLock ()
 
 ~ReentrantLock ()
 
void Unlock () const
 
void Lock () const
 

Private Attributes

pthread_mutex_t lock
 

Friends

template<class T >
class StatusHandler
 
class ReentrantCondition
 

Detailed Description

A reentrant lock.

Definition at line 55 of file ReentrantLock.h.

Constructor & Destructor Documentation

Sync::ReentrantLock::ReentrantLock ( )
inline

Definition at line 57 of file ReentrantLock.h.

References ENSURE, and lock.

57  {
58  pthread_mutexattr_t attr;
59  pthread_mutexattr_init(&attr);
60  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
61  ENSURE(!pthread_mutex_init(&lock, &attr));
62  pthread_mutexattr_destroy(&attr);
63 #ifdef SYNC_PROFILE
64  wait_time = 0;
65  lock_time = 0;
66  lock_count = 0;
67 #endif
68  }
pthread_mutex_t lock
#define ENSURE(exp,...)
Sync::ReentrantLock::~ReentrantLock ( )
inline

Definition at line 69 of file ReentrantLock.h.

References ENSURE_ABORT, and lock.

69  {
70  ENSURE_ABORT(!pthread_mutex_destroy(&lock));
71  }
#define ENSURE_ABORT(exp,...)
pthread_mutex_t lock

Member Function Documentation

void Sync::ReentrantLock::Lock ( void  ) const
inline

Definition at line 83 of file ReentrantLock.h.

References ENSURE_ABORT, and lock.

83  {
84 #ifdef SYNC_PROFILE
85  double start = Internal::getTime();
86 #endif
87  ENSURE_ABORT(!pthread_mutex_lock(&lock));
88 #ifdef SYNC_PROFILE
89  double time = Internal::getTime();
90  if (lock_count == 0) {
91  lock_last = time;
92  }
93  lock_count++;
94  wait_time += time - start;
95 #endif
96  }
#define ENSURE_ABORT(exp,...)
pthread_mutex_t lock
void Sync::ReentrantLock::Unlock ( void  ) const
inline

Definition at line 73 of file ReentrantLock.h.

References ENSURE_ABORT, and lock.

73  {
74 #ifdef SYNC_PROFILE
75  lock_count--;
76  if (lock_count == 0) {
77  lock_time += Internal::getTime() - lock_last;
78  }
79 #endif
80  ENSURE_ABORT(!pthread_mutex_unlock(&lock));
81  }
#define ENSURE_ABORT(exp,...)
pthread_mutex_t lock

Friends And Related Function Documentation

friend class ReentrantCondition
friend

Definition at line 114 of file ReentrantLock.h.

template<class T >
friend class StatusHandler
friend

Definition at line 113 of file ReentrantLock.h.

Member Data Documentation

pthread_mutex_t Sync::ReentrantLock::lock
mutableprivate

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