| 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 |  | 
|---|
| 23 | CCondVarBase::CCondVarBase(CMutex* mutex) : | 
|---|
| 24 | m_mutex(mutex) | 
|---|
| 25 | { | 
|---|
| 26 | assert(m_mutex != NULL); | 
|---|
| 27 | m_cond = ARCH->newCondVar(); | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 | CCondVarBase::~CCondVarBase() | 
|---|
| 31 | { | 
|---|
| 32 | ARCH->closeCondVar(m_cond); | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | void | 
|---|
| 36 | CCondVarBase::lock() const | 
|---|
| 37 | { | 
|---|
| 38 | m_mutex->lock(); | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | void | 
|---|
| 42 | CCondVarBase::unlock() const | 
|---|
| 43 | { | 
|---|
| 44 | m_mutex->unlock(); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | void | 
|---|
| 48 | CCondVarBase::signal() | 
|---|
| 49 | { | 
|---|
| 50 | ARCH->signalCondVar(m_cond); | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | void | 
|---|
| 54 | CCondVarBase::broadcast() | 
|---|
| 55 | { | 
|---|
| 56 | ARCH->broadcastCondVar(m_cond); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | bool | 
|---|
| 60 | CCondVarBase::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 |  | 
|---|
| 71 | bool | 
|---|
| 72 | CCondVarBase::wait(double timeout) const | 
|---|
| 73 | { | 
|---|
| 74 | return ARCH->waitCondVar(m_cond, m_mutex->m_mutex, timeout); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | CMutex* | 
|---|
| 78 | CCondVarBase::getMutex() const | 
|---|
| 79 | { | 
|---|
| 80 | return m_mutex; | 
|---|
| 81 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.