CPN
Computational Process Networks
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
PthreadReadWriteLock Class Reference

#include <PthreadReadWriteLock.h>

+ Inheritance diagram for PthreadReadWriteLock:
+ Collaboration diagram for PthreadReadWriteLock:

Public Member Functions

 PthreadReadWriteLock (int _priorityWrites=1)
 
void ReadLock (void)
 
void WriteLock (void)
 
void ReadUnlock (void)
 
void WriteUnlock (void)
 
int Error (void)
 
void Clear (void)
 

Protected Member Functions

void TrapError (int result)
 

Protected Attributes

int error
 

Private Attributes

PthreadMutex mutex
 
PthreadCondition lockFree
 
int numReaders
 
int writing
 
int noNewReaders
 
int priorityWrites
 

Detailed Description

Definition at line 37 of file PthreadReadWriteLock.h.

Constructor & Destructor Documentation

PthreadReadWriteLock::PthreadReadWriteLock ( int  _priorityWrites = 1)

Definition at line 29 of file PthreadReadWriteLock.cc.

31 : numReaders(0),
32  writing(0),
33  noNewReaders(0),
34  priorityWrites(_priorityWrites)
35 // mutex(), lockFree()
36 {
37 }

Member Function Documentation

void PthreadErrorHandler::Clear ( void  )
inlineinherited

Definition at line 40 of file PthreadErrorHandler.h.

References PthreadErrorHandler::error.

40 { error = 0; }
int PthreadErrorHandler::Error ( void  )
inlineinherited

Definition at line 39 of file PthreadErrorHandler.h.

References PthreadErrorHandler::error.

39 { return error; }
void PthreadReadWriteLock::ReadLock ( void  )

Definition at line 41 of file PthreadReadWriteLock.cc.

References lockFree, mutex, noNewReaders, numReaders, and PthreadCondition::Wait().

Referenced by PthreadReadLockProtected::PthreadReadLockProtected().

43 {
45  while (noNewReaders)
47  numReaders++;
48 }
PthreadCondition & Wait(PthreadMutex &mutex)
PthreadCondition lockFree

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PthreadReadWriteLock::ReadUnlock ( void  )

Definition at line 66 of file PthreadReadWriteLock.cc.

References lockFree, mutex, numReaders, PthreadCondition::Signal(), and PthreadErrorHandler::TrapError().

Referenced by PthreadReadLockProtected::~PthreadReadLockProtected().

68 {
70 
71  if (numReaders<=0) {
72  TrapError(-1);
73  return;
74  }
75 
76  numReaders--;
77  if (!numReaders)
78  lockFree.Signal();
79 }
void TrapError(int result)
PthreadCondition lockFree
PthreadCondition & Signal(void)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PthreadErrorHandler::TrapError ( int  result)
inlineprotectedinherited
void PthreadReadWriteLock::WriteLock ( void  )

Definition at line 52 of file PthreadReadWriteLock.cc.

References lockFree, mutex, noNewReaders, numReaders, priorityWrites, PthreadCondition::Wait(), and writing.

Referenced by PthreadWriteLockProtected::PthreadWriteLockProtected().

54 {
56  if (priorityWrites)
57  noNewReaders = 1;
58  while (writing || numReaders)
60  writing++;
61  noNewReaders = 1;
62 }
PthreadCondition & Wait(PthreadMutex &mutex)
PthreadCondition lockFree

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PthreadReadWriteLock::WriteUnlock ( void  )

Definition at line 83 of file PthreadReadWriteLock.cc.

References PthreadCondition::Broadcast(), lockFree, mutex, noNewReaders, PthreadErrorHandler::TrapError(), and writing.

Referenced by PthreadWriteLockProtected::~PthreadWriteLockProtected().

85 {
87 
88  if (!writing) {
89  TrapError(-1);
90  return;
91  }
92 
93  writing = 0;
94  noNewReaders = 0;
96 }
PthreadCondition & Broadcast(void)
void TrapError(int result)
PthreadCondition lockFree

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

int PthreadErrorHandler::error
protectedinherited
PthreadCondition PthreadReadWriteLock::lockFree
private

Definition at line 51 of file PthreadReadWriteLock.h.

Referenced by ReadLock(), ReadUnlock(), WriteLock(), and WriteUnlock().

PthreadMutex PthreadReadWriteLock::mutex
private

Definition at line 50 of file PthreadReadWriteLock.h.

Referenced by ReadLock(), ReadUnlock(), WriteLock(), and WriteUnlock().

int PthreadReadWriteLock::noNewReaders
private

Definition at line 54 of file PthreadReadWriteLock.h.

Referenced by ReadLock(), WriteLock(), and WriteUnlock().

int PthreadReadWriteLock::numReaders
private

Definition at line 52 of file PthreadReadWriteLock.h.

Referenced by ReadLock(), ReadUnlock(), and WriteLock().

int PthreadReadWriteLock::priorityWrites
private

Definition at line 55 of file PthreadReadWriteLock.h.

Referenced by WriteLock().

int PthreadReadWriteLock::writing
private

Definition at line 53 of file PthreadReadWriteLock.h.

Referenced by WriteLock(), and WriteUnlock().


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