Update README.md
[nemesis.git] / Platform / SharedVal.h
1 /*
2  Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
3
4  Governed by the TrueCrypt License 3.0 the full text of which is contained in
5  the file License.txt included in TrueCrypt binary and source code distribution
6  packages.
7 */
8
9 #ifndef TC_HEADER_Platform_SharedVal
10 #define TC_HEADER_Platform_SharedVal
11
12 #include "PlatformBase.h"
13 #include "Mutex.h"
14
15 namespace TrueCrypt
16 {
17         template <class T>
18         class SharedVal
19         {
20         public:
21                 SharedVal () { }
22                 explicit SharedVal (T value) : Value (value) { }
23                 virtual ~SharedVal () { }
24
25                 operator T ()
26                 {
27                         return Get ();
28                 }
29
30                 T Decrement ()
31                 {
32                         ValMutex.Lock();
33                         T r = --Value;
34                         ValMutex.Unlock();
35                         return r;
36                 }
37
38                 T Get ()
39                 {
40                         ValMutex.Lock();
41                         T r = Value;
42                         ValMutex.Unlock();
43                         return r;
44                 }
45
46                 T Increment ()
47                 {
48                         ValMutex.Lock();
49                         T r = ++Value;
50                         ValMutex.Unlock();
51                         return r;
52                 }
53
54                 void Set (T value)
55                 {
56                         ValMutex.Lock();
57                         Value = value;
58                         ValMutex.Unlock();
59                 }
60
61         protected:
62                 volatile T Value;
63                 Mutex ValMutex;
64
65         private:
66                 SharedVal (const SharedVal &);
67                 SharedVal &operator= (const SharedVal &);
68         };
69 }
70
71 #endif // TC_HEADER_Platform_SharedVal
This page took 0.021465 seconds and 3 git commands to generate. Download a nemesis OSX (sierra+high sierra, tested/working) binary, with fuse-ext3 via e2fsprogs, at this link. application and installer are signed by screwjack, llc. must install fuse with macFUSE layer first.