Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Private Attributes | List of all members
CAConditionVariable Class Reference

#include <CAConditionVariable.hpp>

Inheritance diagram for CAConditionVariable:
Collaboration diagram for CAConditionVariable:

Public Member Functions

 CAConditionVariable ()
 
 ~CAConditionVariable ()
 
SINT32 wait ()
 Waits for a signal or for a timeout. More...
 
SINT32 wait (CAMutex &oMutex)
 Very ugly shortly to be deleted, uncommented function! More...
 
SINT32 wait (CAMutex *pMutex)
 Very ugly shortly to be deleted, uncommented function! More...
 
SINT32 wait (UINT32 msTimeout)
 Waits for a signal or for a timeout. More...
 
SINT32 signal ()
 Signals this object. More...
 
SINT32 broadcast ()
 Signals this object. More...
 
- Public Member Functions inherited from CAMutex
 CAMutex ()
 
virtual ~CAMutex ()
 
SINT32 lock ()
 
SINT32 unlock ()
 

Private Attributes

CAMutexm_pMutex
 
CASemaphore * m_pSemaphore
 
UINT32 m_iSleepers
 

Additional Inherited Members

- Protected Attributes inherited from CAMutex
CASemaphore * m_pMutex
 

Detailed Description

Definition at line 36 of file CAConditionVariable.hpp.

Constructor & Destructor Documentation

◆ CAConditionVariable()

CAConditionVariable::CAConditionVariable ( )
inline

Definition at line 39 of file CAConditionVariable.hpp.

40  {
41  #ifdef HAVE_PTHREAD_CV
42  m_pCondVar=new pthread_cond_t;
43  pthread_cond_init(m_pCondVar,NULL);
44  #else
45  m_pMutex=new CAMutex();
46  m_pSemaphore=new CASemaphore(0);
47  m_iSleepers=0;
48  #endif
49  }
CAMutex()
Definition: CAMutex.cpp:33

References CAMutex::CAMutex(), m_iSleepers, m_pMutex, and m_pSemaphore.

Here is the call graph for this function:

◆ ~CAConditionVariable()

CAConditionVariable::~CAConditionVariable ( )
inline

Definition at line 51 of file CAConditionVariable.hpp.

52  {
53  #ifdef HAVE_PTHREAD_CV
54  pthread_cond_destroy(m_pCondVar);
55  delete m_pCondVar;
56  m_pCondVar = NULL;
57  #else
58  delete m_pMutex;
59  m_pMutex = NULL;
60  delete m_pSemaphore;
61  m_pSemaphore = NULL;
62  #endif
63  }

References m_pMutex, and m_pSemaphore.

Member Function Documentation

◆ broadcast()

SINT32 CAConditionVariable::broadcast ( )
inline

Signals this object.

All threads waiting on this object will awake. Note: lock() must be called before broadcast() and unlock() must be called if proccessing ends.

Definition at line 180 of file CAConditionVariable.hpp.

181  {
182  #ifdef HAVE_PTHREAD_CV
183  if(pthread_cond_broadcast(m_pCondVar)==0)
184  return E_SUCCESS;
185  return E_UNKNOWN;
186  #else
187  m_pMutex->lock();
188  while( m_iSleepers > 0 )
189  {
190  m_pSemaphore->up();
191  m_iSleepers--;
192  }
193  return m_pMutex->unlock();
194  #endif
195  }
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, m_pMutex, m_pSemaphore, and CAMutex::unlock().

Referenced by CAThreadPool::addRequest(), CAThreadPool::destroy(), and CAAccountingDBInterface::releaseConnection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal()

SINT32 CAConditionVariable::signal ( )
inline

Signals this object.

One of the threads waiting on this object will awake. Note: lock() must be called before signal() and unlock() must be called if proccessing ends.

Definition at line 159 of file CAConditionVariable.hpp.

160  {
161  #ifdef HAVE_PTHREAD_CV
162  if(pthread_cond_signal(m_pCondVar)==0)
163  return E_SUCCESS;
164  return E_UNKNOWN;
165  #else
166  m_pMutex->lock();
167  if( m_iSleepers > 0 )
168  {
169  m_pSemaphore->up();
170  m_iSleepers--;
171  }
172  return m_pMutex->unlock();
173  #endif
174  }

References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, m_pMutex, m_pSemaphore, and CAMutex::unlock().

Referenced by CAAccountingInstance::__newSettlementTransaction(), CAQueue::add(), CAQueue::close(), CAFirstMixChannelList::remove(), CAAccountingSettleThread::settle(), CAAccountingInstance::settlementTransaction(), CAInfoService::signal(), CAInfoService::stop(), and CALockAble::unlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait() [1/4]

SINT32 CAConditionVariable::wait ( )
inline

Waits for a signal or for a timeout.

Note: lock() must be called before wait() and unlock() must be called if proccessing ends.

Return values
E_SUCCESSif signaled
E_UNKNOWNif an error occured

Definition at line 71 of file CAConditionVariable.hpp.

72  {
73  #ifdef HAVE_PTHREAD_CV
74  if(pthread_cond_wait(m_pCondVar,m_pMutex)==0)
75  return E_SUCCESS;
76  return E_UNKNOWN;
77  #else
78  m_pMutex->lock();
79  unlock(); // Release the lock that is associated with our cv
80  m_iSleepers++;
81  m_pMutex->unlock();
82  m_pSemaphore->down();
83  return lock();
84  #endif
85  }

References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, m_pMutex, m_pSemaphore, and CAMutex::unlock().

Referenced by CAAccountingInstance::__newSettlementTransaction(), CAThreadPool::addRequest(), CAThreadPool::destroy(), CAAccountingDBInterface::getConnection(), CAQueue::getOrWait(), CAAccountingInstance::handleChallengeResponse_internal(), CAInfoService::InfoLoop(), CAAccountingSettleThread::mainLoop(), CAAccountingInstance::settlementTransaction(), wait(), and CALockAble::waitForDestroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait() [2/4]

SINT32 CAConditionVariable::wait ( CAMutex oMutex)
inline

Very ugly shortly to be deleted, uncommented function!

Definition at line 89 of file CAConditionVariable.hpp.

90  {
91  #ifdef HAVE_PTHREAD_CV
92  if(pthread_cond_wait(m_pCondVar,oMutex.m_pMutex)==0)
93  return E_SUCCESS;
94  return E_UNKNOWN;
95  #else
96  m_pMutex->lock();
97  oMutex.unlock(); // Release the lock that is associated with our cv
98  m_iSleepers++;
99  m_pMutex->unlock();
100  m_pSemaphore->down();
101  return oMutex.lock();
102  #endif
103  }
CASemaphore * m_pMutex
Definition: CAMutex.hpp:69

References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, m_pMutex, CAMutex::m_pMutex, m_pSemaphore, and CAMutex::unlock().

Here is the call graph for this function:

◆ wait() [3/4]

SINT32 CAConditionVariable::wait ( CAMutex pMutex)
inline

Very ugly shortly to be deleted, uncommented function!

Definition at line 107 of file CAConditionVariable.hpp.

108  {
109  #ifdef HAVE_PTHREAD_CV
110  if(pthread_cond_wait(m_pCondVar,pMutex->m_pMutex)==0)
111  return E_SUCCESS;
112  return E_UNKNOWN;
113  #else
114  m_pMutex->lock();
115  pMutex->unlock(); // Release the lock that is associated with our cv
116  m_iSleepers++;
117  m_pMutex->unlock();
118  m_pSemaphore->down();
119  return pMutex->lock();
120  #endif
121  }

References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, m_pMutex, CAMutex::m_pMutex, m_pSemaphore, and CAMutex::unlock().

Here is the call graph for this function:

◆ wait() [4/4]

SINT32 CAConditionVariable::wait ( UINT32  msTimeout)
inline

Waits for a signal or for a timeout.

Note: lock() must be called before wait() and unlock() must be called if proccessing ends.

Parameters
msTimeouttimout value in millis seconds
Return values
E_SUCCESSif signaled
E_TIMEDOUTif timout was reached
E_UNKNOWNif an error occured
Todo:
add something better here....

Definition at line 131 of file CAConditionVariable.hpp.

132  {
133  #ifdef HAVE_PTHREAD_CV
134  timespec to;
135  getcurrentTime(to);
136  to.tv_nsec+=(msTimeout%1000)*1000000;
137  to.tv_sec+=msTimeout/1000;
138  if(to.tv_nsec>999999999)
139  {
140  to.tv_sec++;
141  to.tv_nsec-=1000000000;
142  }
143  int ret=pthread_cond_timedwait(m_pCondVar,m_pMutex,&to);
144  if(ret==0)
145  return E_SUCCESS;
146  else if(ret==ETIMEDOUT)
147  return E_TIMEDOUT;
148  return E_UNKNOWN;
149  #else
151  return wait();
152  #endif
153  }
SINT32 getcurrentTime(timespec &t)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:227
SINT32 wait()
Waits for a signal or for a timeout.
#define E_TIMEDOUT
Definition: errorcodes.hpp:10

References E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTime(), m_pMutex, and wait().

Here is the call graph for this function:

Member Data Documentation

◆ m_iSleepers

UINT32 CAConditionVariable::m_iSleepers
private

Definition at line 203 of file CAConditionVariable.hpp.

Referenced by broadcast(), CAConditionVariable(), signal(), and wait().

◆ m_pMutex

CAMutex* CAConditionVariable::m_pMutex
private

◆ m_pSemaphore

CASemaphore* CAConditionVariable::m_pSemaphore
private

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