• Main Page
  • Classes
  • Files
  • File List

CCondVar.cpp

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

Generated on Wed Jun 19 2013 00:00:05 for Synergy by  doxygen 1.7.1