Equalizer
1.2.1
|
A variable with atomic semantics and standalone atomic operations. More...
#include <atomic.h>
Public Member Functions | |
Atomic (const T v=0) | |
Construct a new atomic variable with an initial value. | |
Atomic (const Atomic< T > &v) | |
Construct a copy of an atomic variable. | |
operator T (void) const | |
void | operator= (const T v) |
Assign a new value. | |
void | operator= (const Atomic< T > &v) |
Assign a new value. | |
T | operator+= (T v) |
Atomically add a value and return the new value. | |
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. | |
T | operator-- (void) |
Atomically decrement by one and return the new value. | |
T | operator++ (int) |
Atomically increment by one and return the old value. | |
T | operator-- (int) |
Atomically decrement by one and return the old value. | |
bool | operator== (const Atomic< T > &rhs) const |
bool | operator!= (const Atomic< T > &rhs) const |
bool | compareAndSwap (const T expected, const T newValue) |
Perform a compare-and-swap atomic operation. | |
Static Public Member Functions | |
static COBASE_API T | getAndAdd (T &value, const T increment) |
static COBASE_API T | getAndSub (T &value, const T increment) |
static T | addAndGet (T &value, const T increment) |
static T | subAndGet (T &value, const T increment) |
static COBASE_API T | incAndGet (T &value) |
static COBASE_API T | decAndGet (T &value) |
static COBASE_API bool | compareAndSwap (T *value, const T expected, const T newValue) |
Perform a compare-and-swap atomic operation. |
A variable with atomic semantics and standalone atomic operations.
Atomic variables can be modified safely from multiple threads concurrently. They are useful to implement lock-free algorithms.
For implementation reasons, only signed atomic variables are supported, of which only int32_t is implemented right now.
co::base::Atomic< T >::Atomic | ( | const T | v = 0 | ) | [explicit] |
co::base::Atomic< T >::Atomic | ( | const Atomic< T > & | v | ) |
T co::base::Atomic< T >::addAndGet | ( | T & | value, |
const T | increment | ||
) | [static] |
bool co::base::Atomic< T >::compareAndSwap | ( | T * | value, |
const T | expected, | ||
const T | newValue | ||
) | [static] |
Perform a compare-and-swap atomic operation.
Definition at line 172 of file atomic.h.
Referenced by co::base::SpinLock::trySet(), co::base::SpinLock::trySetRead(), and co::base::SpinLock::unsetRead().
bool co::base::Atomic< T >::compareAndSwap | ( | const T | expected, |
const T | newValue | ||
) |
T co::base::Atomic< T >::decAndGet | ( | T & | value | ) | [static] |
T co::base::Atomic< T >::getAndAdd | ( | T & | value, |
const T | increment | ||
) | [static] |
T co::base::Atomic< T >::getAndSub | ( | T & | value, |
const T | increment | ||
) | [static] |
T co::base::Atomic< T >::incAndGet | ( | T & | value | ) | [static] |
co::base::Atomic< T >::operator T | ( | void | ) | const |
bool co::base::Atomic< T >::operator!= | ( | const Atomic< T > & | rhs | ) | const |
Definition at line 253 of file atomic.h.
References co::base::memoryBarrier().
T co::base::Atomic< T >::operator++ | ( | void | ) |
T co::base::Atomic< T >::operator++ | ( | int | ) |
T co::base::Atomic< T >::operator+= | ( | T | v | ) |
T co::base::Atomic< T >::operator-- | ( | void | ) |
T co::base::Atomic< T >::operator-- | ( | int | ) |
T co::base::Atomic< T >::operator-= | ( | T | v | ) |
void co::base::Atomic< T >::operator= | ( | const T | v | ) |
Assign a new value.
Definition at line 205 of file atomic.h.
References co::base::memoryBarrier().
void co::base::Atomic< T >::operator= | ( | const Atomic< T > & | v | ) |
Assign a new value.
Not thread-safe!
Definition at line 211 of file atomic.h.
References co::base::memoryBarrier().
bool co::base::Atomic< T >::operator== | ( | const Atomic< T > & | rhs | ) | const |
Definition at line 247 of file atomic.h.
References co::base::memoryBarrier().
T co::base::Atomic< T >::subAndGet | ( | T & | value, |
const T | increment | ||
) | [static] |