Mobile API Reference  MicroStrategy 2019
AtomicLongData.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : AtomicLongData.h
3 // AUTHOR : Jing Ning
4 // CREATION : 2001-09-26
5 // Copyright (C) MicroStrategy Incorporated 2001
6 //==============================================================================================
7 #ifndef MSynch_AtomicLongData_h
8 #define MSynch_AtomicLongData_h
9 
11 #include "../ProtectedSource/InprocessRecursiveMutex.h"
12 
13 namespace MSynch
14 {
15  // This class is all inlined because
16  // 1. It is not exported
17  // 2. It is called very, very frequently and we need to speed it up
19  {
20  public:
21  AtomicLongData(const Int32 inValue = 0):
22  mValue(inValue)
23  {
24  }
25 
26  AtomicLongData(const AtomicLongData& irAtomicLong):
27  mValue(irAtomicLong.mValue)
28  {
29  }
30 
31  Int32 operator++() throw()
32  {
34  return ++mValue;
35  }
36 
37  Int32 AddAndReturnOld(Int32 iValue) throw()
38  {
40  Int32 lRes = mValue;
41  mValue += iValue;
42  return lRes;
43  }
44 
45 
46  Int32 operator--() throw()
47  {
49  return --mValue;
50  }
51 
52  Int32 GetValue() const throw()
53  {
55  return mValue;
56  }
57 
58  // WARNING Assignment operator to atomic long is never thread-safe.
59  // It is meant only for (single-threaded) initialization.
60  // Caller of atomic long must ensure that this call is only used when that atomic
61  // long can only be accessed by a single thread.
62  void operator=(const Int32 inValue)
63  {
65  mValue=inValue;
66  }
67 
68  long Exchange(long inValue)
69  {
71  long lPreviousValue = mValue;
72  mValue = inValue;
73  return lPreviousValue;
74  }
75 
76  private:
77  // disallow assignment operator
78  // assignment is never thread safe
79  Int32 operator=(AtomicLongData& irAtomicLongData);
80 
81  mutable InprocessRecursiveMutex mMutex;
82  Int32 mValue;
83  };
84 }
85 
86 #endif // MSynch_AtomicLongData_h
87 
Int32 GetValue() const
Definition: AtomicLongData.h:52
Definition: AtomicLongData.h:18
Definition: InprocessRecursiveMutex.h:25
void operator=(const Int32 inValue)
Definition: AtomicLongData.h:62
Definition: ReferenceCountedImpl.h:18
Definition: InprocessRecursiveMutex.h:31
long Exchange(long inValue)
Definition: AtomicLongData.h:68
Int32 operator--()
Definition: AtomicLongData.h:46
Int32 operator++()
Definition: AtomicLongData.h:31
#define Int32
Definition: BasicTypes.h:20
Int32 AddAndReturnOld(Int32 iValue)
Definition: AtomicLongData.h:37
AtomicLongData(const AtomicLongData &irAtomicLong)
Definition: AtomicLongData.h:26
AtomicLongData(const Int32 inValue=0)
Definition: AtomicLongData.h:21