CCondVar.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2002 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #ifndef CCONDVAR_H
00016 #define CCONDVAR_H
00017 
00018 #include "CMutex.h"
00019 #include "BasicTypes.h"
00020 
00021 class CStopwatch;
00022 
00024 
00030 class CCondVarBase {
00031 public:
00037     CCondVarBase(CMutex* mutex);
00038     ~CCondVarBase();
00039 
00041 
00042 
00044 
00050     void                lock() const;
00051 
00053     void                unlock() const;
00054 
00056 
00060     void                signal();
00061 
00063 
00066     void                broadcast();
00067 
00069 
00070 
00071 
00073 
00092     bool                wait(double timeout = -1.0) const;
00093 
00095 
00104     bool                wait(CStopwatch& timer, double timeout) const;
00105 
00107 
00110     CMutex*             getMutex() const;
00111 
00113 
00114 private:
00115     // not implemented
00116     CCondVarBase(const CCondVarBase&);
00117     CCondVarBase&       operator=(const CCondVarBase&);
00118 
00119 private:
00120     CMutex*             m_mutex;
00121     CArchCond           m_cond;
00122 };
00123 
00125 
00128 template <class T>
00129 class CCondVar : public CCondVarBase {
00130 public:
00132     CCondVar(CMutex* mutex, const T& value);
00134     CCondVar(const CCondVar&);
00135     ~CCondVar();
00136 
00138 
00139 
00141 
00145     CCondVar&           operator=(const CCondVar& cv);
00146 
00148 
00152     CCondVar&           operator=(const T& v);
00153 
00155 
00156 
00157 
00159 
00163                         operator const volatile T&() const;
00164 
00166 
00167 private:
00168     volatile T          m_data;
00169 };
00170 
00171 template <class T>
00172 inline
00173 CCondVar<T>::CCondVar(
00174     CMutex* mutex,
00175     const T& data) :
00176     CCondVarBase(mutex),
00177     m_data(data)
00178 {
00179     // do nothing
00180 }
00181 
00182 template <class T>
00183 inline
00184 CCondVar<T>::CCondVar(
00185     const CCondVar& cv) :
00186     CCondVarBase(cv.getMutex()),
00187     m_data(cv.m_data)
00188 {
00189     // do nothing
00190 }
00191 
00192 template <class T>
00193 inline
00194 CCondVar<T>::~CCondVar()
00195 {
00196     // do nothing
00197 }
00198 
00199 template <class T>
00200 inline
00201 CCondVar<T>&
00202 CCondVar<T>::operator=(const CCondVar<T>& cv)
00203 {
00204     m_data = cv.m_data;
00205     return *this;
00206 }
00207 
00208 template <class T>
00209 inline
00210 CCondVar<T>&
00211 CCondVar<T>::operator=(const T& data)
00212 {
00213     m_data = data;
00214     return *this;
00215 }
00216 
00217 template <class T>
00218 inline
00219 CCondVar<T>::operator const volatile T&() const
00220 {
00221     return m_data;
00222 }
00223 
00224 #endif

Generated on Fri Nov 6 00:18:44 2009 for synergy-plus by  doxygen 1.4.7