LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Attributes | List of all members
lsst::ap::Condition< MutexT > Class Template Reference

Encapsulates a POSIX condition variable. More...

#include <Condition.h>

Inheritance diagram for lsst::ap::Condition< MutexT >:

Public Types

typedef ScopedLock< MutexT > Lock
 

Public Member Functions

 Condition ()
 
 ~Condition ()
 
void wait (Lock &lock)
 
template<typename P >
void wait (Lock &lock, P predicate)
 
bool wait (Lock &lock, TimeSpec const &ts)
 
template<typename P >
bool wait (Lock &lock, P predicate, TimeSpec const &deadline)
 
void notify ()
 
void notifyAll ()
 
template<>
 Condition ()
 
template<>
 Condition ()
 

Private Attributes

::pthread_cond_t _condition
 

Detailed Description

template<typename MutexT>
class lsst::ap::Condition< MutexT >

Encapsulates a POSIX condition variable.

Definition at line 50 of file Condition.h.

Member Typedef Documentation

template<typename MutexT >
typedef ScopedLock<MutexT> lsst::ap::Condition< MutexT >::Lock

Definition at line 54 of file Condition.h.

Constructor & Destructor Documentation

template<typename MutexT >
lsst::ap::Condition< MutexT >::Condition ( )
template<typename MutexT >
lsst::ap::Condition< MutexT >::~Condition ( )
inline

Definition at line 58 of file Condition.h.

58  {
59  int result = ::pthread_cond_destroy(&_condition);
60  assert(result == 0);
61  }
::pthread_cond_t _condition
Definition: Condition.h:149
template<>
lsst::ap::Condition< Mutex >::Condition ( )

Definition at line 50 of file Condition.cc.

50  {
51  int err = ::pthread_cond_init(&_condition, 0);
52  if (err != 0) {
53  throw LSST_EXCEPT(ex::RuntimeError,
54  (boost::format("pthread_cond_init() failed, return code: %1%") % err).str());
55  }
56 }
::pthread_cond_t _condition
Definition: Condition.h:149
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46

Definition at line 60 of file Condition.cc.

60  {
61  ::pthread_condattr_t attr;
62  int err = ::pthread_condattr_init(&attr);
63  if (err != 0) {
64  throw LSST_EXCEPT(ex::RuntimeError,
65  (boost::format("pthread_condattr_init() failed, return code: %1%") % err).str());
66  }
67  ScopeGuard attrGuard(boost::bind(::pthread_condattr_destroy, &attr));
68  ::pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
69  err = ::pthread_cond_init(&_condition, &attr);
70  if (err != 0) {
71  throw LSST_EXCEPT(ex::RuntimeError,
72  (boost::format("pthread_cond_init() failed, return code: %1%") % err).str());
73  }
74 }
::pthread_cond_t _condition
Definition: Condition.h:149
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46

Member Function Documentation

template<typename MutexT >
void lsst::ap::Condition< MutexT >::notify ( )
inline

Wakes up at least one thread waiting on the condition. For predictable scheduling, the mutex associated with the condition should be acquired prior to calling this method.

Definition at line 133 of file Condition.h.

133  {
134  int result = ::pthread_cond_signal(&_condition);
135  assert(result == 0);
136  }
::pthread_cond_t _condition
Definition: Condition.h:149
template<typename MutexT >
void lsst::ap::Condition< MutexT >::notifyAll ( )
inline

Wakes up all threads waiting on the condition. For predictable scheduling, the mutex associated with the condition should be acquired prior to calling this method.

Definition at line 142 of file Condition.h.

142  {
143  int result = ::pthread_cond_broadcast(&_condition);
144  assert(result == 0);
145  }
::pthread_cond_t _condition
Definition: Condition.h:149
template<typename MutexT >
void lsst::ap::Condition< MutexT >::wait ( Lock lock)
inline

Waits on the condition variable until the calling thread is woken as a result of another thread calling notify() or notifyAll(). Spurious wakeup can occur.

Precondition
lock has been successfully acquired

Definition at line 69 of file Condition.h.

69  {
70  assert(lock.isAcquired());
71  int result = ::pthread_cond_wait(&_condition, lock.getPosixMutex());
72  assert(result == 0);
73  }
::pthread_cond_t _condition
Definition: Condition.h:149
template<typename MutexT >
template<typename P >
void lsst::ap::Condition< MutexT >::wait ( Lock lock,
predicate 
)
inline

Waits on the condition variable until the given predicate evaluates to true.

Precondition
lock has been successfully acquired

Definition at line 81 of file Condition.h.

82  {
83  assert(lock.isAcquired());
84  while (!predicate()) {
85  int result = ::pthread_cond_wait(&_condition, lock.getPosixMutex());
86  assert(result == 0);
87  }
88  }
::pthread_cond_t _condition
Definition: Condition.h:149
template<typename MutexT >
bool lsst::ap::Condition< MutexT >::wait ( Lock lock,
TimeSpec const &  ts 
)
inline

Waits on this condition variable until either the given deadline expires or the calling thread is woken as a result of another thread calling notify() or notifyAll(). Spurious wakeup can occur.

Precondition
lock has been successfully acquired
Returns
false if the deadline was missed, and true otherwise.

Definition at line 98 of file Condition.h.

98  {
99  assert(lock.isAcquired());
100  int result = ::pthread_cond_timedwait(&_condition, lock.getPosixMutex(), &ts);
101  if (result == ETIMEDOUT) {
102  return false;
103  }
104  assert(result == 0);
105  return true;
106  }
::pthread_cond_t _condition
Definition: Condition.h:149
template<typename MutexT >
template<typename P >
bool lsst::ap::Condition< MutexT >::wait ( Lock lock,
predicate,
TimeSpec const &  deadline 
)
inline

Waits on this condition variable until the given predicate evaluates to true or the given deadline is missed.

Precondition
lock has been successfully acquired
Returns
true if the predicate became true before the deadline expired, and false if the deadline was missed.

Definition at line 117 of file Condition.h.

117  {
118  assert(lock.isAcquired());
119  while (!predicate()) {
120  int result = ::pthread_cond_timedwait(&_condition, lock.getPosixMutex(), &deadline);
121  if (result == ETIMEDOUT) {
122  return false;
123  }
124  assert(result == 0);
125  }
126  return true;
127  }
::pthread_cond_t _condition
Definition: Condition.h:149

Member Data Documentation

template<typename MutexT >
::pthread_cond_t lsst::ap::Condition< MutexT >::_condition
private

Definition at line 149 of file Condition.h.


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