Plasma Engine  2.0
Loading...
Searching...
No Matches
AtomicInteger_inl.h
1
2template <typename T>
4 : m_Value(0)
5{
6}
7
8template <typename T>
9PL_ALWAYS_INLINE plAtomicInteger<T>::plAtomicInteger(T value)
10 : m_Value(static_cast<UnderlyingType>(value))
11{
12}
13
14template <typename T>
16 : m_Value(plAtomicUtils::Read(value.m_Value))
17{
18}
19
20template <typename T>
21PL_ALWAYS_INLINE plAtomicInteger<T>& plAtomicInteger<T>::operator=(const T value)
22{
23 Set(value);
24 return *this;
25}
26
27template <typename T>
29{
30 Set(plAtomicUtils::Read(value.m_Value));
31 return *this;
32}
33
34template <typename T>
36{
37 return static_cast<T>(plAtomicUtils::Increment(m_Value));
38}
39
40template <typename T>
42{
43 return static_cast<T>(plAtomicUtils::Decrement(m_Value));
44}
45
46template <typename T>
48{
49 return static_cast<T>(plAtomicUtils::PostIncrement(m_Value));
50}
51
52template <typename T>
54{
55 return static_cast<T>(plAtomicUtils::PostDecrement(m_Value));
56}
57
58template <typename T>
59PL_ALWAYS_INLINE void plAtomicInteger<T>::Add(T x)
60{
61 plAtomicUtils::Add(m_Value, static_cast<UnderlyingType>(x));
62}
63
64template <typename T>
65PL_ALWAYS_INLINE void plAtomicInteger<T>::Subtract(T x)
66{
67 plAtomicUtils::Add(m_Value, -static_cast<UnderlyingType>(x));
68}
69
70template <typename T>
71PL_ALWAYS_INLINE void plAtomicInteger<T>::And(T x)
72{
73 plAtomicUtils::And(m_Value, static_cast<UnderlyingType>(x));
74}
75
76template <typename T>
77PL_ALWAYS_INLINE void plAtomicInteger<T>::Or(T x)
78{
79 plAtomicUtils::Or(m_Value, static_cast<UnderlyingType>(x));
80}
81
82template <typename T>
83PL_ALWAYS_INLINE void plAtomicInteger<T>::Xor(T x)
84{
85 plAtomicUtils::Xor(m_Value, static_cast<UnderlyingType>(x));
87
88template <typename T>
89PL_ALWAYS_INLINE void plAtomicInteger<T>::Min(T x)
91 plAtomicUtils::Min(m_Value, static_cast<UnderlyingType>(x));
92}
93
94template <typename T>
95PL_ALWAYS_INLINE void plAtomicInteger<T>::Max(T x)
96{
97 plAtomicUtils::Max(m_Value, static_cast<UnderlyingType>(x));
98}
99
100template <typename T>
101PL_ALWAYS_INLINE T plAtomicInteger<T>::Set(T x)
102{
103 return static_cast<T>(plAtomicUtils::Set(m_Value, static_cast<UnderlyingType>(x)));
104}
105
106template <typename T>
107PL_ALWAYS_INLINE bool plAtomicInteger<T>::TestAndSet(T expected, T x)
108{
109 return plAtomicUtils::TestAndSet(m_Value, static_cast<UnderlyingType>(expected), static_cast<UnderlyingType>(x));
110}
111
112template <typename T>
113PL_ALWAYS_INLINE T plAtomicInteger<T>::CompareAndSwap(T expected, T x)
114{
115 return static_cast<T>(plAtomicUtils::CompareAndSwap(m_Value, static_cast<UnderlyingType>(expected), static_cast<UnderlyingType>(x)));
116}
117
118template <typename T>
119PL_ALWAYS_INLINE plAtomicInteger<T>::operator T() const
120{
121 return static_cast<T>(plAtomicUtils::Read(m_Value));
122}
123
125
126PL_ALWAYS_INLINE plAtomicBool::plAtomicBool() = default;
127PL_ALWAYS_INLINE plAtomicBool::~plAtomicBool() = default;
128
129PL_ALWAYS_INLINE plAtomicBool::plAtomicBool(bool value)
130{
131 Set(value);
132}
133
134PL_ALWAYS_INLINE plAtomicBool::plAtomicBool(const plAtomicBool& rhs)
135{
136 Set(static_cast<bool>(rhs));
137}
138
139PL_ALWAYS_INLINE bool plAtomicBool::Set(bool value)
140{
141 return m_iAtomicInt.Set(value ? 1 : 0) != 0;
142}
143
144PL_ALWAYS_INLINE void plAtomicBool::operator=(bool value)
145{
146 Set(value);
147}
148
149PL_ALWAYS_INLINE void plAtomicBool::operator=(const plAtomicBool& rhs)
150{
151 Set(static_cast<bool>(rhs));
152}
153
154PL_ALWAYS_INLINE plAtomicBool::operator bool() const
155{
156 return static_cast<plInt32>(m_iAtomicInt) != 0;
157}
158
159PL_ALWAYS_INLINE bool plAtomicBool::TestAndSet(bool bExpected, bool bNewValue)
160{
161 return m_iAtomicInt.TestAndSet(bExpected ? 1 : 0, bNewValue ? 1 : 0) != 0;
162}
An atomic boolean variable. This is just a wrapper around an atomic int32 for convenience.
Definition AtomicInteger.h:100
bool Set(bool value)
Sets the bool to the given value and returns its previous value.
Definition AtomicInteger_inl.h:139
plAtomicBool()
Initializes the bool to 'false'.
void operator=(bool value)
Sets the bool to the given value.
Definition AtomicInteger_inl.h:144
bool TestAndSet(bool bExpected, bool bNewValue)
Sets the internal value to newValue if the internal value is equal to expected and returns true,...
Definition AtomicInteger_inl.h:159
Integer class that can be manipulated in an atomic (i.e. thread-safe) fashion.
Definition AtomicInteger.h:39
bool TestAndSet(T expected, T x)
Sets the internal value to x if the internal value is equal to expected and returns true,...
Definition AtomicInteger_inl.h:107
T Increment()
Increments the internal value and returns the incremented value.
Definition AtomicInteger_inl.h:35
plAtomicInteger & operator=(T value)
Assigns a new integer value to this object.
Definition AtomicInteger_inl.h:21
T PostDecrement()
Decrements the internal value and returns the value immediately before the decrement.
Definition AtomicInteger_inl.h:53
T Decrement()
Decrements the internal value and returns the decremented value.
Definition AtomicInteger_inl.h:41
T Set(T x)
Sets the internal value to x and returns the original internal value.
Definition AtomicInteger_inl.h:101
T PostIncrement()
Increments the internal value and returns the value immediately before the increment.
Definition AtomicInteger_inl.h:47
T CompareAndSwap(T expected, T x)
If this is equal to expected, it is set to value. Otherwise it won't be modified. Always returns the ...
Definition AtomicInteger_inl.h:113
plAtomicInteger()
Initializes the value to zero.
Definition AtomicInteger_inl.h:3
This class provides functions to do atomic operations.
Definition AtomicUtils.h:15
static plInt32 Decrement(plInt32 &ref_iDest)
Decrements dest as an atomic operation and returns the new value.
Definition AtomicUtils_posix.h:31
static void Add(plInt32 &ref_iDest, plInt32 value)
Adds value to dest as an atomic operation.
Definition AtomicUtils_posix.h:62
static plInt32 CompareAndSwap(plInt32 &ref_iDest, plInt32 iExpected, plInt32 value)
If dest is equal to expected, this function sets dest to value. Otherwise dest will not be modified....
Definition AtomicUtils_posix.h:192
static void Or(plInt32 &ref_iDest, plInt32 value)
Performs an atomic bitwise OR on dest using value.
Definition AtomicUtils_posix.h:84
static plInt32 Read(const plInt32 &iSrc)
Returns src as an atomic operation and returns its value.
Definition AtomicUtils_posix.h:10
static void Min(plInt32 &ref_iDest, plInt32 value)
Performs an atomic min operation on dest using value.
Definition AtomicUtils_posix.h:106
static void And(plInt32 &ref_iDest, plInt32 value)
Performs an atomic bitwise AND on dest using value.
Definition AtomicUtils_posix.h:73
static void Xor(plInt32 &ref_iDest, plInt32 value)
Performs an atomic bitwise XOR on dest using value.
Definition AtomicUtils_posix.h:95
static plInt32 PostIncrement(plInt32 &ref_iDest)
Increments dest as an atomic operation and returns the old value.
Definition AtomicUtils_posix.h:41
static plInt32 Increment(plInt32 &ref_iDest)
Increments dest as an atomic operation and returns the new value.
Definition AtomicUtils_posix.h:20
static void Max(plInt32 &ref_iDest, plInt32 value)
Performs an atomic max operation on dest using value.
Definition AtomicUtils_posix.h:133
static plInt32 PostDecrement(plInt32 &ref_iDest)
Decrements dest as an atomic operation and returns the old value.
Definition AtomicUtils_posix.h:52
static plInt32 Set(plInt32 &ref_iDest, plInt32 value)
Sets dest to value as an atomic operation and returns the original value of dest.
Definition AtomicUtils_posix.h:160
static bool TestAndSet(plInt32 &ref_iDest, plInt32 iExpected, plInt32 value)
If dest is equal to expected, this function sets dest to value and returns true. Otherwise dest will ...
Definition AtomicUtils_posix.h:171