source: trunk/synergy/lib/mt/CCondVar.cpp@ 3232

Last change on this file since 3232 was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 1.4 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2002 Chris Schoeneman
4 *
5 * This package is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include "CCondVar.h"
16#include "CStopwatch.h"
17#include "CArch.h"
18
19//
20// CCondVarBase
21//
22
23CCondVarBase::CCondVarBase(CMutex* mutex) :
24 m_mutex(mutex)
25{
26 assert(m_mutex != NULL);
27 m_cond = ARCH->newCondVar();
28}
29
30CCondVarBase::~CCondVarBase()
31{
32 ARCH->closeCondVar(m_cond);
33}
34
35void
36CCondVarBase::lock() const
37{
38 m_mutex->lock();
39}
40
41void
42CCondVarBase::unlock() const
43{
44 m_mutex->unlock();
45}
46
47void
48CCondVarBase::signal()
49{
50 ARCH->signalCondVar(m_cond);
51}
52
53void
54CCondVarBase::broadcast()
55{
56 ARCH->broadcastCondVar(m_cond);
57}
58
59bool
60CCondVarBase::wait(CStopwatch& timer, double timeout) const
61{
62 // check timeout against timer
63 if (timeout >= 0.0) {
64 timeout -= timer.getTime();
65 if (timeout < 0.0)
66 return false;
67 }
68 return wait(timeout);
69}
70
71bool
72CCondVarBase::wait(double timeout) const
73{
74 return ARCH->waitCondVar(m_cond, m_mutex->m_mutex, timeout);
75}
76
77CMutex*
78CCondVarBase::getMutex() const
79{
80 return m_mutex;
81}
Note: See TracBrowser for help on using the repository browser.