fesa-core
7.0.0
|
#include <Atomic.h>
Inherits noncopyable.
Inherited by fesa::AtomicInteger< T >.
Public Member Functions | |
Atomic (T initialValue=0) | |
Atomic (char *memory, bool aligned, T initialValue=0, bool ignoreInitialValue=false) | |
T | load () const |
void | store (T value) |
bool | compareAndExchange (T &expected, const T desired) |
Static Public Member Functions | |
static void | checkAlignment (const char *pointer) |
Static Public Attributes | |
static const std::size_t | alignment = sizeof(T) |
static const std::size_t | unalignedSize = Aligned<T>::unalignedSize |
Static Protected Member Functions | |
static boost::atomic< T > * | alignAndCreate (char *memory, T initialValue, bool ignoreInitialValue=false) |
static boost::atomic< T > * | create (char *memory, T initialValue, bool ignoreInitialValue=false) |
Protected Attributes | |
boost::atomic< T > * | value_ |
bool | mine_ |
Wrapper class for atomic types. Can either use preexisting memory, or allocate it. All operations on Atomic<T> objects are guaranteed to be atomic. Additionally, all operations on Atomic<T> objects instantiated on preexisting memory are guaranteed to be lock-free. Instantiable with all integral types (bool included) from 8 to 64 bits.
|
explicit |
Allocates and creates an atomic type.
initialValue | the initial value |
fesa::Atomic< T >::Atomic | ( | char * | memory, |
bool | aligned, | ||
T | initialValue = 0 , |
||
bool | ignoreInitialValue = false |
||
) |
Creates an atomic type from arbitrary memory. The memory buffer given must satisfy one of these conditions: A. Have a size of sizeof(T) and be aligned properly (for x86 and x64, this means aligned on sizeof(T)) B. Have a size of Atomic<T>::unalignedSize; the alignment doesn't matter then. In case A, the aligned parameter must be true; in case B, it must be false. Additionally, in case A, alignment will be checked and an exception thrown if the pointer is unaligned.
memory | pointer to the memory to use |
aligned | whether the memory pointer is properly aligned |
initialValue | the initial value to give to this object. If not given, object is initialized to 0. |
ignoreInitialValue | if true, the atomic created is left uninitialized. |
FesaException | if aligned is true, but memory is not properly aligned. |
FesaException | if current platform doesn't support lock-free atomic operations on T. |
|
staticprotected |
Allocates a boost::atomic<T> on the memory pointer given, ensuring proper alignment. The memory pointer must point to a memory buffer of at least Atomic<T>::unalignedSize bytes.
memory | pointer to a buffer where the atomic type will be allocated |
initialValue | initial value to give to the object |
ignoreInitialValue | if true, the atomic created is left uninitialized. |
|
static |
Checks the alignment of pointer and throws if it is not properly aligned for T.
pointer | the pointer to check |
|
inline |
Stores the desired value in the object only if its current value is equal to the expected value. In all cases, writes the previous value to expected.
expected | the expected value of the object |
desired | the desired value to store in the object |
|
staticprotected |
Allocates a boost::atomic<T> on the memory pointer given. The pointer must be properly aligned. Alignment is checked and this function will throw if it is not correct. The size of the buffer pointed to by memory must be at least sizeof(T) bytes.
memory | pointer to a buffer where the atomic type will be allocated |
initialValue | initial value to give to the object |
ignoreInitialValue | if true, the atomic created is left uninitialized. |
|
inline |
|
inline |
Stores the given value in the object.
value | the value to store. |
|
static |
Contains the required alignment for T.
|
protected |
Whether memory was allocated by this object or given as a paremeter to the constructor
|
static |
Contains the required unaligned memory size to ensure an aligned T can be allocated.
|
protected |
Pointer to the wrapped atomic type