|
Mixe for Privacy and Anonymity in the Internet
|
#include <CAConditionVariable.hpp>
Public Member Functions | |
| CAConditionVariable () | |
| ~CAConditionVariable () | |
| SINT32 | wait () |
| Waits for a signal or for a timeout. | |
| SINT32 | wait (CAMutex &oMutex) |
| Very ugly shortly to be deleted, uncommented function! | |
| SINT32 | wait (CAMutex *pMutex) |
| Very ugly shortly to be deleted, uncommented function! | |
| SINT32 | wait (UINT32 msTimeout) |
| Waits for a signal or for a timeout. | |
| SINT32 | signal () |
| Signals this object. | |
| SINT32 | broadcast () |
| Signals this object. | |
Private Attributes | |
| CAMutex * | m_pMutex |
| CASemaphore * | m_pSemaphore |
| UINT32 | m_iSleepers |
Definition at line 36 of file CAConditionVariable.hpp.
| CAConditionVariable::CAConditionVariable | ( | ) | [inline] |
Definition at line 39 of file CAConditionVariable.hpp.
References CAMutex::CAMutex(), m_iSleepers, m_pMutex, and m_pSemaphore.
{
#ifdef HAVE_PTHREAD_CV
m_pCondVar=new pthread_cond_t;
pthread_cond_init(m_pCondVar,NULL);
#else
m_pMutex=new CAMutex();
m_pSemaphore=new CASemaphore(0);
m_iSleepers=0;
#endif
}
| CAConditionVariable::~CAConditionVariable | ( | ) | [inline] |
Definition at line 51 of file CAConditionVariable.hpp.
References m_pMutex, and m_pSemaphore.
{
#ifdef HAVE_PTHREAD_CV
pthread_cond_destroy(m_pCondVar);
delete m_pCondVar;
m_pCondVar = NULL;
#else
delete m_pMutex;
m_pMutex = NULL;
delete m_pSemaphore;
m_pSemaphore = NULL;
#endif
}
| 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.
References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, m_pMutex, m_pSemaphore, and CAMutex::unlock().
Referenced by CAThreadPool::addRequest(), CAThreadPool::destroy(), CAAccountingDBInterface::releaseConnection(), and worker_thread_main_loop().
{
#ifdef HAVE_PTHREAD_CV
if(pthread_cond_broadcast(m_pCondVar)==0)
return E_SUCCESS;
return E_UNKNOWN;
#else
m_pMutex->lock();
while( m_iSleepers > 0 )
{
m_pSemaphore->up();
m_iSleepers--;
}
return m_pMutex->unlock();
#endif
}
| 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.
References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, m_pMutex, m_pSemaphore, and CAMutex::unlock().
Referenced by CAAccountingInstance::__newSettlementTransaction(), CAQueue::add(), CAFirstMixChannelList::remove(), CAAccountingSettleThread::settle(), CAAccountingInstance::settlementTransaction(), CAInfoService::signal(), CAInfoService::stop(), CALockAble::unlock(), and worker_thread_main_loop().
{
#ifdef HAVE_PTHREAD_CV
if(pthread_cond_signal(m_pCondVar)==0)
return E_SUCCESS;
return E_UNKNOWN;
#else
m_pMutex->lock();
if( m_iSleepers > 0 )
{
m_pSemaphore->up();
m_iSleepers--;
}
return m_pMutex->unlock();
#endif
}
| 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.
| E_SUCCESS | if signaled |
| E_UNKNOWN | if an error occured |
Definition at line 71 of file CAConditionVariable.hpp.
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(), CALockAble::waitForDestroy(), and worker_thread_main_loop().
{
#ifdef HAVE_PTHREAD_CV
if(pthread_cond_wait(m_pCondVar,m_pMutex)==0)
return E_SUCCESS;
return E_UNKNOWN;
#else
m_pMutex->lock();
unlock(); // Release the lock that is associated with our cv
m_iSleepers++;
m_pMutex->unlock();
m_pSemaphore->down();
return lock();
#endif
}
| SINT32 CAConditionVariable::wait | ( | CAMutex & | oMutex | ) | [inline] |
Very ugly shortly to be deleted, uncommented function!
Definition at line 89 of file CAConditionVariable.hpp.
References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, CAMutex::m_pMutex, m_pMutex, m_pSemaphore, and CAMutex::unlock().
{
#ifdef HAVE_PTHREAD_CV
if(pthread_cond_wait(m_pCondVar,oMutex.m_pMutex)==0)
return E_SUCCESS;
return E_UNKNOWN;
#else
m_pMutex->lock();
oMutex.unlock(); // Release the lock that is associated with our cv
m_iSleepers++;
m_pMutex->unlock();
m_pSemaphore->down();
return oMutex.lock();
#endif
}
| SINT32 CAConditionVariable::wait | ( | CAMutex * | pMutex | ) | [inline] |
Very ugly shortly to be deleted, uncommented function!
Definition at line 107 of file CAConditionVariable.hpp.
References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_iSleepers, CAMutex::m_pMutex, m_pMutex, m_pSemaphore, and CAMutex::unlock().
{
#ifdef HAVE_PTHREAD_CV
if(pthread_cond_wait(m_pCondVar,pMutex->m_pMutex)==0)
return E_SUCCESS;
return E_UNKNOWN;
#else
m_pMutex->lock();
pMutex->unlock(); // Release the lock that is associated with our cv
m_iSleepers++;
m_pMutex->unlock();
m_pSemaphore->down();
return pMutex->lock();
#endif
}
| 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.
| msTimeout | timout value in millis seconds |
| E_SUCCESS | if signaled |
| E_TIMEDOUT | if timout was reached |
| E_UNKNOWN | if an error occured |
Definition at line 131 of file CAConditionVariable.hpp.
References E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTime(), m_pMutex, and wait().
{
#ifdef HAVE_PTHREAD_CV
timespec to;
getcurrentTime(to);
to.tv_nsec+=(msTimeout%1000)*1000000;
to.tv_sec+=msTimeout/1000;
if(to.tv_nsec>999999999)
{
to.tv_sec++;
to.tv_nsec-=1000000000;
}
int ret=pthread_cond_timedwait(m_pCondVar,m_pMutex,&to);
if(ret==0)
return E_SUCCESS;
else if(ret==ETIMEDOUT)
return E_TIMEDOUT;
return E_UNKNOWN;
#else
return wait();
#endif
}
UINT32 CAConditionVariable::m_iSleepers [private] |
Definition at line 203 of file CAConditionVariable.hpp.
Referenced by broadcast(), CAConditionVariable(), signal(), and wait().
CAMutex* CAConditionVariable::m_pMutex [private] |
Reimplemented from CAMutex.
Definition at line 201 of file CAConditionVariable.hpp.
Referenced by broadcast(), CAConditionVariable(), signal(), wait(), and ~CAConditionVariable().
CASemaphore* CAConditionVariable::m_pSemaphore [private] |
Definition at line 202 of file CAConditionVariable.hpp.
Referenced by broadcast(), CAConditionVariable(), signal(), wait(), and ~CAConditionVariable().
1.7.6.1