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

#include <PthreadMutex.h>

+ Inheritance diagram for PthreadMutex:
+ Collaboration diagram for PthreadMutex:

Public Member Functions

 PthreadMutex (void)
 
 PthreadMutex (const PthreadMutexAttr &attr)
 
 ~PthreadMutex (void)
 
 operator pthread_mutex_t * ()
 
 operator const pthread_mutex_t * () const
 
PthreadMutex & Lock (void)
 
PthreadMutex & Unlock (void)
 
PthreadMutex & Take (void)
 
PthreadMutex & Give (void)
 
bool Poll (void)
 
int Error (void)
 
void Clear (void)
 

Protected Member Functions

void TrapError (int result)
 

Protected Attributes

int error
 

Private Attributes

pthread_mutex_t theMutex
 

Detailed Description

Definition at line 40 of file PthreadMutex.h.

Constructor & Destructor Documentation

PthreadMutex::PthreadMutex ( void  )

Definition at line 33 of file PthreadMutex.cc.

References theMutex, and PthreadErrorHandler::TrapError().

36 {
37  TrapError(pthread_mutex_init(&theMutex, 0));
38 }
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
void TrapError(int result)

+ Here is the call graph for this function:

PthreadMutex::PthreadMutex ( const PthreadMutexAttr &  attr)

Definition at line 42 of file PthreadMutex.cc.

References theMutex, and PthreadErrorHandler::TrapError().

44 {
45  // It should simply be:
46 // TrapError(pthread_mutex_init(&theMutex, mAttr));
47 
48  // This is necessary because
49  // SGI's pthread_mutex_init is not const correct!!!
50 
51  pthread_mutexattr_t* myAttr = (PthreadMutexAttr&)mAttr;
52  TrapError(pthread_mutex_init(&theMutex, myAttr));
53 }
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
void TrapError(int result)

+ Here is the call graph for this function:

PthreadMutex::~PthreadMutex ( void  )

Definition at line 57 of file PthreadMutex.cc.

References theMutex, and PthreadErrorHandler::TrapError().

59 {
60  try {
61  TrapError(pthread_mutex_destroy(&theMutex));
62  } catch (...) {
63  std::terminate();
64  }
65 }
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
void TrapError(int result)

+ Here is the call graph for this function:

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; }
PthreadMutex& PthreadMutex::Give ( void  )
inline

Definition at line 52 of file PthreadMutex.h.

References Unlock().

Referenced by PthreadMutexProtected::~PthreadMutexProtected().

52 { return Unlock(); }
PthreadMutex & Unlock(void)
Definition: PthreadMutex.h:50

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PthreadMutex& PthreadMutex::Lock ( void  )
inline

Definition at line 49 of file PthreadMutex.h.

References theMutex, and PthreadErrorHandler::TrapError().

Referenced by CPN::QueueBase::Lock(), and Take().

49 { TrapError(pthread_mutex_lock(&theMutex)); return *this; }
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
void TrapError(int result)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PthreadMutex::operator const pthread_mutex_t * ( ) const
inline

Definition at line 47 of file PthreadMutex.h.

References theMutex.

47 { return &theMutex; }
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
PthreadMutex::operator pthread_mutex_t * ( )
inline

Definition at line 46 of file PthreadMutex.h.

References theMutex.

46 { return &theMutex; }
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
bool PthreadMutex::Poll ( void  )

Definition at line 69 of file PthreadMutex.cc.

References theMutex, and PthreadErrorHandler::TrapError().

71 { int err = pthread_mutex_trylock(&theMutex);
72  if(err == EBUSY)
73  return false;
74  TrapError(err);
75  return true;
76 }
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
void TrapError(int result)

+ Here is the call graph for this function:

PthreadMutex& PthreadMutex::Take ( void  )
inline

Definition at line 51 of file PthreadMutex.h.

References Lock().

Referenced by PthreadMutexProtected::PthreadMutexProtected().

51 { return Lock(); }
PthreadMutex & Lock(void)
Definition: PthreadMutex.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PthreadErrorHandler::TrapError ( int  result)
inlineprotectedinherited
PthreadMutex& PthreadMutex::Unlock ( void  )
inline

Definition at line 50 of file PthreadMutex.h.

References theMutex, and PthreadErrorHandler::TrapError().

Referenced by Give(), and CPN::QueueBase::Unlock().

50 { TrapError(pthread_mutex_unlock(&theMutex)); return *this; }
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
void TrapError(int result)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

int PthreadErrorHandler::error
protectedinherited
pthread_mutex_t PthreadMutex::theMutex
private

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