2009-02-27 14:54:59 +03:00
|
|
|
/*
|
2011-01-15 07:01:31 +03:00
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
|
2009-02-27 14:54:59 +03:00
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2010-06-20 21:38:51 +04:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-02-27 14:54:59 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "CCondVar.h"
|
|
|
|
#include "CStopwatch.h"
|
|
|
|
#include "CArch.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// CCondVarBase
|
|
|
|
//
|
|
|
|
|
|
|
|
CCondVarBase::CCondVarBase(CMutex* mutex) :
|
|
|
|
m_mutex(mutex)
|
|
|
|
{
|
|
|
|
assert(m_mutex != NULL);
|
|
|
|
m_cond = ARCH->newCondVar();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCondVarBase::~CCondVarBase()
|
|
|
|
{
|
|
|
|
ARCH->closeCondVar(m_cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CCondVarBase::lock() const
|
|
|
|
{
|
|
|
|
m_mutex->lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CCondVarBase::unlock() const
|
|
|
|
{
|
|
|
|
m_mutex->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CCondVarBase::signal()
|
|
|
|
{
|
|
|
|
ARCH->signalCondVar(m_cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CCondVarBase::broadcast()
|
|
|
|
{
|
|
|
|
ARCH->broadcastCondVar(m_cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CCondVarBase::wait(CStopwatch& timer, double timeout) const
|
|
|
|
{
|
|
|
|
// check timeout against timer
|
|
|
|
if (timeout >= 0.0) {
|
|
|
|
timeout -= timer.getTime();
|
|
|
|
if (timeout < 0.0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return wait(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CCondVarBase::wait(double timeout) const
|
|
|
|
{
|
|
|
|
return ARCH->waitCondVar(m_cond, m_mutex->m_mutex, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMutex*
|
|
|
|
CCondVarBase::getMutex() const
|
|
|
|
{
|
|
|
|
return m_mutex;
|
|
|
|
}
|