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

FXMutex.h
1 /********************************************************************************
2 * *
3 * M u t e x C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2004,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXMUTEX_H
22 #define FXMUTEX_H
23 
24 namespace FX {
25 
26 
31 class FXAPI FXMutex {
32  friend class FXCondition;
33 private:
34  FXuval data[24];
35 private:
36  FXMutex(const FXMutex&);
37  FXMutex &operator=(const FXMutex&);
38 public:
39 
44  FXMutex(FXbool recursive=false);
45 
47  void lock();
48 
50  FXbool trylock();
51 
53  FXbool locked();
54 
56  void unlock();
57 
59  ~FXMutex();
60  };
61 
62 
71 class FXAPI FXScopedMutex {
72 private:
73  FXMutex& mtx;
74 private:
75  FXScopedMutex();
77  FXScopedMutex& operator=(const FXScopedMutex&);
78 public:
79 
81  FXScopedMutex(FXMutex& m):mtx(m){ lock(); }
82 
84  FXMutex& mutex(){ return mtx; }
85 
87  void lock(){ mtx.lock(); }
88 
90  FXbool trylock(){ return mtx.trylock(); }
91 
93  FXbool locked(){ return mtx.locked(); }
94 
96  void unlock(){ mtx.unlock(); }
97 
99  ~FXScopedMutex(){ unlock(); }
100  };
101 
102 
109 class FXAPI FXReverseMutex {
110 private:
111  FXMutex& mtx;
112 private:
113  FXReverseMutex();
115  FXReverseMutex& operator=(const FXReverseMutex&);
116 public:
117 
119  FXReverseMutex(FXMutex& m):mtx(m){ unlock(); }
120 
122  FXMutex& mutex(){ return mtx; }
123 
125  void lock(){ mtx.lock(); }
126 
128  FXbool trylock(){ return mtx.trylock(); }
129 
131  FXbool locked(){ return mtx.locked(); }
132 
134  void unlock(){ mtx.unlock(); }
135 
137  ~FXReverseMutex(){ lock(); }
138  };
139 
140 
141 }
142 
143 #endif
144 

Copyright © 1997-2016 Jeroen van der Zijp