15 #ifndef LUNCHBOX_ATOMIC_H 16 #define LUNCHBOX_ATOMIC_H 19 #include <lunchbox/compiler.h> 24 #pragma warning(disable : 4985) // inconsistent decl of ceil 28 #pragma intrinsic(_ReadWriteBarrier) 29 #elif defined(__xlC__) 41 #elif defined(_MSC_VER) 43 #elif defined(__xlC__) 48 #error "no memory barrier implemented for this platform" 91 LUNCHBOX_API
static T
getAndAdd(T& value,
const T increment);
94 LUNCHBOX_API
static T
getAndSub(T& value,
const T increment);
97 static T
addAndGet(T& value,
const T increment);
100 static T
subAndGet(T& value,
const T increment);
103 LUNCHBOX_API
static T
incAndGet(T& value);
106 LUNCHBOX_API
static T
decAndGet(T& value);
109 LUNCHBOX_API
static bool compareAndSwap(T* value,
const T expected,
113 explicit Atomic(
const T v = 0);
119 operator T(
void)
const;
166 LB_ALIGN8(
mutable T _value);
175 return __sync_fetch_and_add(&value, increment);
181 return __sync_fetch_and_sub(&value, increment);
187 return __sync_add_and_fetch(&value, increment);
193 return __sync_sub_and_fetch(&value, increment);
211 return __sync_bool_compare_and_swap(value, expected, newValue);
214 #elif defined(_MSC_VER) 220 return getAndAdd(value, increment) + increment;
226 return getAndSub(value, increment) - increment;
234 return __compare_and_swap(value, const_cast<T*>(&expected), newValue);
239 const int64_t expected,
240 const int64_t newValue)
242 return __compare_and_swaplp(value, const_cast<int64_t*>(&expected),
247 #error No compare-and-swap implementated for this platform 256 const T oldv = value;
257 const T newv = oldv + increment;
272 const T oldv = value;
273 const T newv = oldv - increment;
288 const T oldv = value;
289 const T newv = oldv + increment;
304 const T oldv = value;
305 const T newv = oldv - increment;
400 return _value == rhs._value;
407 return _value != rhs._value;
416 #endif // LUNCHBOX_ATOMIC_H static T decAndGet(T &value)
static T getAndSub(T &value, const T increment)
A variable with atomic semantics and standalone atomic operations.
Defines export visibility macros for library Lunchbox.
Basic type definitions not provided by the operating system.
void memoryBarrierRelease()
Perform a store-with-release memory barrier.
static T getAndAdd(T &value, const T increment)
static T addAndGet(T &value, const T increment)
static T incAndGet(T &value)
bool operator!=(const Atomic< T > &rhs) const
T operator--(void)
Atomically decrement by one and return the new value.
static T subAndGet(T &value, const T increment)
static bool compareAndSwap(T *value, const T expected, const T newValue)
Perform a compare-and-swap atomic operation.
void memoryBarrier()
Perform a full memory barrier.
bool operator==(const Atomic< T > &rhs) const
void operator=(const T v)
Assign a new value.
T operator+=(T v)
Atomically add a value and return the new value.
Atomic(const T v=0)
Construct a new atomic variable with an initial value.
void memoryBarrierAcquire()
Perform a load-with-acquire memory barrier.
Abstraction layer and common utilities for multi-threaded programming.
T operator-=(T v)
Atomically substract a value and return the new value.
T operator++(void)
Atomically increment by one and return the new value.