00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "CCondVar.h"
00020 #include "CStopwatch.h"
00021 #include "CArch.h"
00022
00023
00024
00025
00026
00027 CCondVarBase::CCondVarBase(CMutex* mutex) :
00028 m_mutex(mutex)
00029 {
00030 assert(m_mutex != NULL);
00031 m_cond = ARCH->newCondVar();
00032 }
00033
00034 CCondVarBase::~CCondVarBase()
00035 {
00036 ARCH->closeCondVar(m_cond);
00037 }
00038
00039 void
00040 CCondVarBase::lock() const
00041 {
00042 m_mutex->lock();
00043 }
00044
00045 void
00046 CCondVarBase::unlock() const
00047 {
00048 m_mutex->unlock();
00049 }
00050
00051 void
00052 CCondVarBase::signal()
00053 {
00054 ARCH->signalCondVar(m_cond);
00055 }
00056
00057 void
00058 CCondVarBase::broadcast()
00059 {
00060 ARCH->broadcastCondVar(m_cond);
00061 }
00062
00063 bool
00064 CCondVarBase::wait(CStopwatch& timer, double timeout) const
00065 {
00066
00067 if (timeout >= 0.0) {
00068 timeout -= timer.getTime();
00069 if (timeout < 0.0)
00070 return false;
00071 }
00072 return wait(timeout);
00073 }
00074
00075 bool
00076 CCondVarBase::wait(double timeout) const
00077 {
00078 return ARCH->waitCondVar(m_cond, m_mutex->m_mutex, timeout);
00079 }
00080
00081 CMutex*
00082 CCondVarBase::getMutex() const
00083 {
00084 return m_mutex;
00085 }