33 template <
size_t SizeOf>
39 typedef char Integral;
42 template <
class Atomic,
class Target>
43 static void read(
volatile Atomic* atomic, Target* target)
45 *(Integral*) target = *(
volatile Integral*) atomic;
50 template <
class Atomic,
class Addend>
51 static void add(
volatile Atomic* atomic, Addend* addend)
53 const Integral addendValue = *
static_cast<Integral*
>(addend);
55 *(Integral*) addend = (_InterlockedExchangeAdd8((
volatile Integral*) atomic, addendValue) + addendValue);
58 template <
class Atomic,
class Value>
59 static void store(
volatile Atomic* atomic,
const Value*
value)
61 _InterlockedExchange8((
volatile Integral*) atomic, *(
const Integral*) value);
64 template <
class Atomic,
class Value>
65 static void exchange(
volatile Atomic* atomic, Value* value)
67 *(Integral*) value = _InterlockedExchange8((
volatile Integral*) atomic, *
static_cast<Integral*
>(
value));
70 template <
class Atomic,
class Comparand,
class Value>
71 static bool compareExchange(
volatile Atomic* atomic, Comparand* comparand,
const Value* value)
73 const Integral comparandValue = *(Integral*) comparand;
75 const Integral previous =
76 _InterlockedCompareExchange8((
volatile Integral*) atomic, *(
const Integral*) value, comparandValue);
78 if (previous == comparandValue)
83 *(Integral*) value = previous;
92 typedef short Integral;
95 template <
class Atomic,
class Target>
96 static void read(
volatile Atomic* atomic, Target* target)
98 *(Integral*) target = *(
volatile Integral*) atomic;
103 template <
class Atomic,
class Addend>
104 static void add(
volatile Atomic* atomic, Addend* addend)
106 const Integral addendValue = *
static_cast<Integral*
>(addend);
108 *(Integral*) addend = (_InterlockedExchangeAdd16((
volatile Integral*) atomic, addendValue) + addendValue);
111 template <
class Atomic,
class Value>
112 static void store(
volatile Atomic* atomic,
const Value* value)
114 _InterlockedExchange16((
volatile Integral*) atomic, *(
const Integral*) value);
117 template <
class Atomic,
class Value>
118 static void exchange(
volatile Atomic* atomic, Value* value)
120 *(Integral*) value = _InterlockedExchange16((
volatile Integral*) atomic, *
static_cast<Integral*
>(
value));
123 template <
class Atomic,
class Comparand,
class Value>
124 static bool compareExchange(
volatile Atomic* atomic, Comparand* comparand,
const Value* value)
126 const Integral comparandValue = *(Integral*) comparand;
128 const Integral previous =
129 _InterlockedCompareExchange16((
volatile Integral*) atomic, *(
const Integral*) value, comparandValue);
131 if (previous == comparandValue)
136 *(Integral*) value = previous;
145 typedef long Integral;
148 template <
class Atomic,
class Target>
149 static void read(
volatile Atomic* atomic, Target* target)
151 *(Integral*) target = *(
volatile Integral*) atomic;
156 template <
class Atomic,
class Addend>
157 static void add(
volatile Atomic* atomic, Addend* addend)
159 const Integral addendValue = *
static_cast<Integral*
>(addend);
161 *(Integral*) addend = (_InterlockedExchangeAdd((
volatile Integral*) atomic, addendValue) + addendValue);
164 template <
class Atomic,
class Value>
165 static void store(
volatile Atomic* atomic,
const Value* value)
167 _InterlockedExchange((
volatile Integral*) atomic, *(
const Integral*) value);
170 template <
class Atomic,
class Value>
171 static void exchange(
volatile Atomic* atomic, Value* value)
173 *(Integral*) value = _InterlockedExchange((
volatile Integral*) atomic, *
static_cast<Integral*
>(
value));
176 template <
class Atomic,
class Comparand,
class Value>
177 static bool compareExchange(
volatile Atomic* atomic, Comparand* comparand,
const Value* value)
179 const Integral comparandValue = *(Integral*) comparand;
181 const Integral previous =
182 _InterlockedCompareExchange((
volatile Integral*) atomic, *(
const Integral*) value, comparandValue);
184 if (previous == comparandValue)
189 *(Integral*) value = previous;
198 typedef long long Integral;
201 template <
class Atomic,
class Target>
202 static void read(
volatile Atomic* atomic, Target* target)
204 *(Integral*) target = *(
volatile Integral*) atomic;
209 template <
class Atomic,
class Addend>
210 static void add(
volatile Atomic* atomic, Addend* addend)
212 const Integral addendValue = *
static_cast<Integral*
>(addend);
214 *(Integral*) addend = (_InterlockedExchangeAdd64((
volatile Integral*) atomic, addendValue) + addendValue);
217 template <
class Atomic,
class Value>
218 static void store(
volatile Atomic* atomic,
const Value* value)
220 _InterlockedExchange64((
volatile Integral*) atomic, *(
const Integral*) value);
223 template <
class Atomic,
class Value>
224 static void exchange(
volatile Atomic* atomic, Value* value)
226 *(Integral*) value = _InterlockedExchange64((
volatile Integral*) atomic, *
static_cast<Integral*
>(
value));
229 template <
class Atomic,
class Comparand,
class Value>
230 static bool compareExchange(
volatile Atomic* atomic, Comparand* comparand,
const Value* value)
232 const Integral comparandValue = *(Integral*) comparand;
234 const Integral previous =
235 _InterlockedCompareExchange64((
volatile Integral*) atomic, *(
const Integral*) value, comparandValue);
237 if (previous == comparandValue)
242 *(Integral*) value = previous;
250 template <
typename Type>
253 static Type read(
volatile Type& atomic)
257 AtomicOps<sizeof(Type)>::read(&atomic, &
value);
262 static void store(
volatile Type& atomic, Type value)
264 AtomicOps<sizeof(Type)>::store(&atomic, &
value);
267 static void exchange(
volatile Type& atomic, Type& value)
269 AtomicOps<sizeof(Type)>::exchange(&atomic, &
value);
272 static bool compareStore(
volatile Type& atomic, Type comparand, Type value)
274 return AtomicOps<sizeof(Type)>::compareExchange(&atomic, &comparand, &
value);
277 static bool compareExchange(
volatile Type& atomic, Type comparand, Type& value)
279 return AtomicOps<sizeof(Type)>::compareExchange(&atomic, &comparand, &
value);
283 #elif defined(__GNUC__) 285 template <
typename Type>
288 static Type read(
volatile Type& atomic)
290 const Type value = atomic;
292 __sync_synchronize();
297 static void store(
volatile Type& atomic, Type value)
299 (void) (__sync_lock_test_and_set(&atomic, value));
302 static void exchange(
volatile Type& atomic, Type& value)
304 value = __sync_lock_test_and_set(&atomic, value);
307 static bool compareStore(
volatile Type& atomic, Type comparand, Type value)
309 return __sync_bool_compare_and_swap(&atomic, comparand, value);
312 static bool compareExchange(
volatile Type& atomic, Type comparand, Type& value)
314 const Type oldValue = __sync_val_compare_and_swap(&atomic, comparand, value);
316 if (oldValue == comparand)
325 #endif // Toolset selector. 327 template <
typename Type, Type Value>
332 : variable_(variable)
338 Atomic<Type>::store(variable_, Value);
342 volatile Type& variable_;
AtomicScopedStore(volatile Type &variable)
bool value(Number &number, const MultiContainer &container, Tag tag)
Finds a tag-value entry in the given collection by the given tag and returns its value component tran...
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
#define ONIXS_CMEMDH_NAMESPACE_END