23 #include <boost/utility.hpp>
30 template <
typename T,
typename IsTLarge =
void>
31 class AtomicIntrinsics {
33 static T compareAndSwap(
volatile T* dest, T expected, T newValue) {
34 return __sync_val_compare_and_swap(dest, expected, newValue);
37 static T swap(
volatile T* dest, T newValue) {
38 T currentValue = *dest;
40 const T result = compareAndSwap(dest, currentValue, newValue);
41 if (result == currentValue)
43 currentValue = result;
47 static T load(
volatile const T* value) {
54 static T loadRelaxed(
volatile const T* value) {
55 asm volatile(
"" :::
"memory");
59 static void store(
volatile T* dest, T newValue) {
65 static T fetchAndAdd(
volatile T* dest, T increment) {
66 return __sync_fetch_and_add(dest, increment);
75 class AtomicIntrinsics<T, typename boost::disable_if_c<sizeof(T) <= sizeof(void*)>::type> {
77 static T compareAndSwap(
volatile T* dest, T expected, T newValue) {
78 return __sync_val_compare_and_swap(dest, expected, newValue);
81 static T swap(
volatile T* dest, T newValue) {
82 T currentValue = *dest;
84 const T result = compareAndSwap(dest, currentValue, newValue);
85 if (result == currentValue)
87 currentValue = result;
91 static T load(
volatile const T* value) {
92 return compareAndSwap(const_cast<volatile T*>(value), T(0), T(0));
95 static void store(
volatile T* dest, T newValue) {
99 static T fetchAndAdd(
volatile T* dest, T increment) {
100 return __sync_fetch_and_add(dest, increment);
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20