|
|
1.1 root 1: /*
2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
3:
1.1.1.4 ! root 4: Governed by the TrueCrypt License 2.7 the full text of which is contained
1.1 root 5: in the file License.txt included in TrueCrypt binary and source code
6: distribution 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 archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.