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

#include <CAConditionVariable.hpp>

Inheritance diagram for CAConditionVariable:
[legend]
Collaboration diagram for CAConditionVariable:
[legend]

List of all members.

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

CAMutexm_pMutex
CASemaphore * m_pSemaphore
UINT32 m_iSleepers

Detailed Description

Definition at line 36 of file CAConditionVariable.hpp.


Constructor & Destructor Documentation

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
        }

Here is the call graph for this function:

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
        }

Member Function Documentation

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
        }

Here is the call graph for this function:

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
        }

Here is the call graph for this function:

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.

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
        }

Here is the call graph for this function:

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
        }

Here is the call graph for this function:

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
        }

Here is the call graph for this function:

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.

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
        }

Here is the call graph for this function:


Member Data Documentation

Definition at line 203 of file CAConditionVariable.hpp.

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

Reimplemented from CAMutex.

Definition at line 201 of file CAConditionVariable.hpp.

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

CASemaphore* CAConditionVariable::m_pSemaphore [private]

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