• Main Page
  • Classes
  • Files
  • File List

CCondVar.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2002 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef CCONDVAR_H
00020 #define CCONDVAR_H
00021 
00022 #include "CMutex.h"
00023 #include "BasicTypes.h"
00024 
00025 class CStopwatch;
00026 
00028 
00034 class CCondVarBase {
00035 public:
00041     CCondVarBase(CMutex* mutex);
00042     ~CCondVarBase();
00043 
00045 
00046 
00048 
00054     void                lock() const;
00055 
00057     void                unlock() const;
00058 
00060 
00064     void                signal();
00065 
00067 
00070     void                broadcast();
00071 
00073 
00074 
00075 
00077 
00096     bool                wait(double timeout = -1.0) const;
00097 
00099 
00108     bool                wait(CStopwatch& timer, double timeout) const;
00109 
00111 
00114     CMutex*             getMutex() const;
00115 
00117 
00118 private:
00119     // not implemented
00120     CCondVarBase(const CCondVarBase&);
00121     CCondVarBase&       operator=(const CCondVarBase&);
00122 
00123 private:
00124     CMutex*             m_mutex;
00125     CArchCond           m_cond;
00126 };
00127 
00129 
00132 template <class T>
00133 class CCondVar : public CCondVarBase {
00134 public:
00136     CCondVar(CMutex* mutex, const T& value);
00138     CCondVar(const CCondVar&);
00139     ~CCondVar();
00140 
00142 
00143 
00145 
00149     CCondVar&           operator=(const CCondVar& cv);
00150 
00152 
00156     CCondVar&           operator=(const T& v);
00157 
00159 
00160 
00161 
00163 
00167                         operator const volatile T&() const;
00168 
00170 
00171 private:
00172     volatile T          m_data;
00173 };
00174 
00175 template <class T>
00176 inline
00177 CCondVar<T>::CCondVar(
00178     CMutex* mutex,
00179     const T& data) :
00180     CCondVarBase(mutex),
00181     m_data(data)
00182 {
00183     // do nothing
00184 }
00185 
00186 template <class T>
00187 inline
00188 CCondVar<T>::CCondVar(
00189     const CCondVar& cv) :
00190     CCondVarBase(cv.getMutex()),
00191     m_data(cv.m_data)
00192 {
00193     // do nothing
00194 }
00195 
00196 template <class T>
00197 inline
00198 CCondVar<T>::~CCondVar()
00199 {
00200     // do nothing
00201 }
00202 
00203 template <class T>
00204 inline
00205 CCondVar<T>&
00206 CCondVar<T>::operator=(const CCondVar<T>& cv)
00207 {
00208     m_data = cv.m_data;
00209     return *this;
00210 }
00211 
00212 template <class T>
00213 inline
00214 CCondVar<T>&
00215 CCondVar<T>::operator=(const T& data)
00216 {
00217     m_data = data;
00218     return *this;
00219 }
00220 
00221 template <class T>
00222 inline
00223 CCondVar<T>::operator const volatile T&() const
00224 {
00225     return m_data;
00226 }
00227 
00228 #endif

Generated on Mon May 20 2013 00:00:05 for Synergy by  doxygen 1.7.1