00001 /* 00002 * synergy -- mouse and keyboard sharing utility 00003 * Copyright (C) 2002 Chris Schoeneman 00004 * 00005 * This package is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * found in the file COPYING that should have accompanied this file. 00008 * 00009 * This package is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 */ 00014 00015 #include "CCondVar.h" 00016 #include "CStopwatch.h" 00017 #include "CArch.h" 00018 00019 // 00020 // CCondVarBase 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 // check timeout against timer 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 }