6 #ifndef TURI_ATOMIC_OPS_HPP 7 #define TURI_ATOMIC_OPS_HPP 28 return __sync_bool_compare_and_swap(&a, oldval, newval);
48 return __sync_bool_compare_and_swap(&a, oldval, newval);
66 return __sync_val_compare_and_swap(&a, oldval, newval);
86 return __sync_val_compare_and_swap(&a, oldval, newval);
106 volatile uint64_t* a_ptr =
reinterpret_cast<volatile uint64_t*
>(&a);
107 const uint64_t* oldval_ptr =
reinterpret_cast<const uint64_t*
>(&oldval);
108 const uint64_t* newval_ptr =
reinterpret_cast<const uint64_t*
>(&newval);
109 return __sync_bool_compare_and_swap(a_ptr, *oldval_ptr, *newval_ptr);
129 volatile uint32_t* a_ptr =
reinterpret_cast<volatile uint32_t*
>(&a);
130 const uint32_t* oldval_ptr =
reinterpret_cast<const uint32_t*
>(&oldval);
131 const uint32_t* newval_ptr =
reinterpret_cast<const uint32_t*
>(&newval);
132 return __sync_bool_compare_and_swap(a_ptr, *oldval_ptr, *newval_ptr);
143 b = __sync_lock_test_and_set(&a, b);
154 b = __sync_lock_test_and_set(&a, b);
163 return __sync_lock_test_and_set(&a, newval);
190 }
while(v < new_value);
221 }
while(v < new_value);
250 }
while(v > new_value);
279 }
while(v > new_value);
291 template<
typename T,
typename U =
int>
293 typename std::enable_if<std::is_integral<T>::value && std::is_integral<U>::value>::type* = 0) {
294 return __sync_fetch_and_add(&value, increment);
306 template<
typename T,
typename U =
int>
308 typename std::enable_if<std::is_integral<T>::value && std::is_integral<U>::value>::type* = 0) {
309 return __sync_fetch_and_add(&value, increment);
static T atomic_increment(T &value, const U &increment=1, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type *=0)
T atomic_set_min(T &min_value, T new_value)
T atomic_compare_and_swap_val(T &a, T oldval, T newval)
bool atomic_compare_and_swap(T &a, T oldval, T newval)
T fetch_and_store(T &a, const T &newval)
Atomically sets a to the newval, returning the old value.
T atomic_set_max(T &max_value, T new_value)
void atomic_exchange(T &a, T &b)
Atomically exchanges the values of a and b.