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