1#ifdef PL_ATOMICUTLS_POSIX_INL_H_INCLUDED
2# error "This file must not be included twice."
5#define PL_ATOMICUTLS_POSIX_INL_H_INCLUDED
8#include <Foundation/Math/Math.h>
12 return __sync_fetch_and_or(
const_cast<plInt32*
>(&src), 0);
17 return __sync_fetch_and_or_8(
const_cast<plInt64*
>(&src), 0);
22 return __sync_add_and_fetch(&dest, 1);
27 return __sync_add_and_fetch_8(&dest, 1);
33 return __sync_sub_and_fetch(&dest, 1);
38 return __sync_sub_and_fetch_8(&dest, 1);
43 return __sync_fetch_and_add(&dest, 1);
48 return __sync_fetch_and_add_8(&dest, 1);
54 return __sync_fetch_and_sub(&dest, 1);
59 return __sync_fetch_and_sub_8(&dest, 1);
64 __sync_fetch_and_add(&dest, value);
69 __sync_fetch_and_add_8(&dest, value);
75 __sync_fetch_and_and(&dest, value);
80 __sync_fetch_and_and_8(&dest, value);
86 __sync_fetch_and_or(&dest, value);
91 __sync_fetch_and_or_8(&dest, value);
97 __sync_fetch_and_xor(&dest, value);
102 __sync_fetch_and_xor_8(&dest, value);
111 plInt32 iOldValue = dest;
114 if (__sync_bool_compare_and_swap(&dest, iOldValue, iNewValue))
124 plInt64 iOldValue = dest;
127 if (__sync_bool_compare_and_swap_8(&dest, iOldValue, iNewValue))
138 plInt32 iOldValue = dest;
141 if (__sync_bool_compare_and_swap(&dest, iOldValue, iNewValue))
151 plInt64 iOldValue = dest;
154 if (__sync_bool_compare_and_swap_8(&dest, iOldValue, iNewValue))
162 return __sync_lock_test_and_set(&dest, value);
167 return __sync_lock_test_and_set_8(&dest, value);
173 return __sync_bool_compare_and_swap(&dest, expected, value);
178 return __sync_bool_compare_and_swap_8(&dest, expected, value);
183#if PL_ENABLED(PL_PLATFORM_64BIT)
184 plUInt64* puiTemp =
reinterpret_cast<plUInt64*
>(dest);
185 return __sync_bool_compare_and_swap(puiTemp,
reinterpret_cast<plUInt64
>(expected),
reinterpret_cast<plUInt64
>(value));
187 plUInt32* puiTemp =
reinterpret_cast<plUInt32*
>(dest);
188 return __sync_bool_compare_and_swap(puiTemp,
reinterpret_cast<plUInt32
>(expected),
reinterpret_cast<plUInt32
>(value));
194 return __sync_val_compare_and_swap(&dest, expected, value);
199 return __sync_val_compare_and_swap_8(&dest, expected, value);
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
constexpr PL_ALWAYS_INLINE T Max(T f1, T f2)
Returns the greater value, f1 or f2.
Definition Math_inl.h:39
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