Annotation of truecrypt/platform/sharedval.h, revision 1.1.1.7

1.1       root        1: /*
1.1.1.6   root        2:  Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
1.1       root        3: 
1.1.1.7 ! root        4:  Governed by the TrueCrypt License 3.0 the full text of which is contained in
1.1.1.6   root        5:  the file License.txt included in TrueCrypt binary and source code distribution
                      6:  packages.
1.1       root        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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.