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

#include <PthreadCondition.h>

+ Inheritance diagram for PthreadCondition:
+ Collaboration diagram for PthreadCondition:

Public Member Functions

 PthreadCondition (void)
 
 PthreadCondition (const PthreadConditionAttr &condattr)
 
 ~PthreadCondition (void)
 
 operator pthread_cond_t * (void)
 
PthreadConditionSignal (void)
 
PthreadConditionBroadcast (void)
 
PthreadConditionWait (PthreadMutex &mutex)
 
int TimedWait (PthreadMutex &mutex, const timespec *abstime)
 
int TimedWait (PthreadMutex &mutex, double reltime)
 
int Error (void)
 
void Clear (void)
 

Protected Member Functions

void TrapError (int result)
 

Protected Attributes

int error
 

Private Attributes

pthread_cond_t theCond
 

Detailed Description

Definition at line 40 of file PthreadCondition.h.

Constructor & Destructor Documentation

PthreadCondition::PthreadCondition ( void  )

Definition at line 32 of file PthreadCondition.cc.

References theCond, and PthreadErrorHandler::TrapError().

35 {
36  TrapError(pthread_cond_init(&theCond, 0));
37 }
pthread_cond_t theCond
void TrapError(int result)

+ Here is the call graph for this function:

PthreadCondition::PthreadCondition ( const PthreadConditionAttr condattr)

Definition at line 41 of file PthreadCondition.cc.

References theCond, and PthreadErrorHandler::TrapError().

43 {
44  // It should simply be:
45 // TrapError(pthread_cond_init(&theCond, cAttr));
46 
47  // This is necessary because
48  // SGI's pthread_cond_init is not const correct!!!
49 
50  pthread_condattr_t* myAttr = (PthreadConditionAttr&)cAttr;
51  TrapError(pthread_cond_init(&theCond, myAttr));
52 }
pthread_cond_t theCond
void TrapError(int result)

+ Here is the call graph for this function:

PthreadCondition::~PthreadCondition ( void  )

Definition at line 56 of file PthreadCondition.cc.

References theCond, and PthreadErrorHandler::TrapError().

58 {
59  try {
60  TrapError(pthread_cond_destroy(&theCond));
61  } catch (...) {
62  std::terminate();
63  }
64 }
pthread_cond_t theCond
void TrapError(int result)

+ Here is the call graph for this function:

Member Function Documentation

PthreadCondition & PthreadCondition::Broadcast ( void  )
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; }
PthreadCondition::operator pthread_cond_t * ( void  )
inline

Definition at line 47 of file PthreadCondition.h.

References theCond.

47 { return &theCond; }
pthread_cond_t theCond
PthreadCondition & PthreadCondition::Signal ( void  )

Definition at line 68 of file PthreadCondition.cc.

References theCond, and PthreadErrorHandler::TrapError().

Referenced by CPN::RemoteQueueHolder::CleanupQueue(), and PthreadReadWriteLock::ReadUnlock().

70 { TrapError(pthread_cond_signal(&theCond));
71  return *this;
72 }
pthread_cond_t theCond
void TrapError(int result)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int PthreadCondition::TimedWait ( PthreadMutex mutex,
const timespec *  abstime 
)

Definition at line 91 of file PthreadCondition.cc.

References theCond, and PthreadErrorHandler::TrapError().

93 {
94  int err = pthread_cond_timedwait(&theCond, mutex, abstime);
95  if (err != 0) {
96  if (err == ETIMEDOUT) { return true; }
97  TrapError(err);
98  }
99  return false;
100 }
pthread_cond_t theCond
void TrapError(int result)

+ Here is the call graph for this function:

int PthreadCondition::TimedWait ( PthreadMutex mutex,
double  reltime 
)

Definition at line 103 of file PthreadCondition.cc.

References theCond, and PthreadErrorHandler::TrapError().

105 {
106  timespec ts;
107  timeval tv;
108  int ret = gettimeofday(&tv, 0);
109  if (ret != 0) throw ErrnoException();
110  ts.tv_sec = tv.tv_sec;
111  ts.tv_nsec = tv.tv_usec * 1000;
112  unsigned sec = (unsigned)reltime;
113  if (sec > 0) {
114  ts.tv_sec += sec;
115  unsigned nsec = (unsigned)((reltime - sec)*1e9);
116  if (nsec > 0) ts.tv_nsec += nsec;
117  }
118  int err = pthread_cond_timedwait(&theCond, mutex, &ts);
119  if (err != 0) {
120  if (err == ETIMEDOUT) { return true; }
121  TrapError(err);
122  }
123  return false;
124 }
pthread_cond_t theCond
void TrapError(int result)

+ Here is the call graph for this function:

void PthreadErrorHandler::TrapError ( int  result)
inlineprotectedinherited
PthreadCondition & PthreadCondition::Wait ( PthreadMutex mutex)

Member Data Documentation

int PthreadErrorHandler::error
protectedinherited
pthread_cond_t PthreadCondition::theCond
private

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