deskflow/src/lib/mt/CondVar.cpp

86 lines
1.6 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Bolton Software Ltd.
* Copyright (C) 2002 Chris Schoeneman
2012-06-10 16:50:54 +00: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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mt/CondVar.h"
#include "arch/Arch.h"
#include "base/Stopwatch.h"
2012-06-10 16:50:54 +00:00
//
2014-11-11 13:51:47 +00:00
// CondVarBase
2012-06-10 16:50:54 +00:00
//
2014-11-11 13:51:47 +00:00
CondVarBase::CondVarBase(Mutex* mutex) :
2012-06-10 16:50:54 +00:00
m_mutex(mutex)
{
assert(m_mutex != NULL);
m_cond = ARCH->newCondVar();
}
2014-11-11 13:51:47 +00:00
CondVarBase::~CondVarBase()
2012-06-10 16:50:54 +00:00
{
ARCH->closeCondVar(m_cond);
}
void
2014-11-11 13:51:47 +00:00
CondVarBase::lock() const
2012-06-10 16:50:54 +00:00
{
m_mutex->lock();
}
void
2014-11-11 13:51:47 +00:00
CondVarBase::unlock() const
2012-06-10 16:50:54 +00:00
{
m_mutex->unlock();
}
void
2014-11-11 13:51:47 +00:00
CondVarBase::signal()
2012-06-10 16:50:54 +00:00
{
ARCH->signalCondVar(m_cond);
}
void
2014-11-11 13:51:47 +00:00
CondVarBase::broadcast()
2012-06-10 16:50:54 +00:00
{
ARCH->broadcastCondVar(m_cond);
}
bool
2014-11-11 13:51:47 +00:00
CondVarBase::wait(Stopwatch& timer, double timeout) const
2012-06-10 16:50:54 +00:00
{
// check timeout against timer
if (timeout >= 0.0) {
timeout -= timer.getTime();
if (timeout < 0.0)
return false;
}
return wait(timeout);
}
bool
2014-11-11 13:51:47 +00:00
CondVarBase::wait(double timeout) const
2012-06-10 16:50:54 +00:00
{
return ARCH->waitCondVar(m_cond, m_mutex->m_mutex, timeout);
}
2014-11-11 13:51:47 +00:00
Mutex*
CondVarBase::getMutex() const
2012-06-10 16:50:54 +00:00
{
return m_mutex;
}