Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXMutex.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                              M u t e x   C l a s s                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2004,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXMUTEX_H
00022 #define FXMUTEX_H
00023 
00024 
00025 namespace FX {
00026 
00027 
00032 class FXAPI FXMutex {
00033   friend class FXCondition;
00034 private:
00035   volatile FXuval data[24];
00036 private:
00037   FXMutex(const FXMutex&);
00038   FXMutex &operator=(const FXMutex&);
00039 public:
00040 
00045   FXMutex(FXbool recursive=false);
00046 
00048   void lock();
00049 
00051   FXbool trylock();
00052 
00054   FXbool locked();
00055 
00057   void unlock();
00058 
00060   ~FXMutex();
00061   };
00062 
00063 
00072 class FXAPI FXScopedMutex {
00073 private:
00074   FXMutex& mtx;
00075 private:
00076   FXScopedMutex();
00077   FXScopedMutex(const FXScopedMutex&);
00078   FXScopedMutex& operator=(const FXScopedMutex&);
00079 public:
00080 
00082   FXScopedMutex(FXMutex& m):mtx(m){ lock(); }
00083 
00085   FXMutex& mutex(){ return mtx; }
00086 
00088   void lock(){ mtx.lock(); }
00089 
00091   FXbool trylock(){ return mtx.trylock(); }
00092 
00094   FXbool locked(){ return mtx.locked(); }
00095 
00097   void unlock(){ mtx.unlock(); }
00098 
00100   ~FXScopedMutex(){ unlock(); }
00101   };
00102 
00103 
00104 // DEPRECATED
00105 typedef FXScopedMutex FXMutexLock;
00106 
00107 }
00108 
00109 #endif
00110 

Copyright © 1997-2011 Jeroen van der Zijp