15 #ifndef IMPALA_COMMON_ATOMIC_H
16 #define IMPALA_COMMON_ATOMIC_H
33 asm volatile(
"pause\n": : :
"memory");
50 operator T()
const {
return value_; }
62 __sync_add_and_fetch(&
value_, delta);
66 __sync_add_and_fetch(&
value_, -delta);
71 __sync_or_and_fetch(&
value_, v);
75 __sync_and_and_fetch(&
value_, v);
81 __sync_add_and_fetch(&
value_, 1);
85 __sync_add_and_fetch(&
value_, -1);
91 T prev = __sync_fetch_and_add(&
value_, 1);
95 T prev = __sync_fetch_and_add(&
value_, -1);
101 return __sync_fetch_and_add(&
value_, 0);
106 return __sync_add_and_fetch(&
value_, delta);
111 return __sync_fetch_and_add(&
value_, delta);
118 T new_value = std::max(old_value, value);
125 T new_value = std::min(old_value, value);
132 return __sync_bool_compare_and_swap(&
value_, old_val, new_val);
138 return __sync_val_compare_and_swap(&
value_, old_val, new_val);
143 return __sync_lock_test_and_set(&
value_, new_val);
T UpdateAndFetch(T delta)
Increments by delta (i.e. += delta) and returns the new val.
AtomicInt< T > operator++(int)
This is post increment, which needs to return a new object.
AtomicInt & operator+=(T delta)
AtomicInt< T > operator--(int)
AtomicInt & operator|=(T v)
T Swap(const T &new_val)
Atomically updates value_ with new_val. Returns the old value_.
T FetchAndUpdate(T delta)
Increment by delta and returns the old val.
void UpdateMax(T value)
Updates the int to 'value' if value is larger.
T CompareAndSwapVal(T old_val, T new_val)
T Read()
Safe read of the value.
AtomicInt & operator=(T val)
bool CompareAndSwap(T old_val, T new_val)
Returns true if the atomic compare-and-swap was successful.
AtomicInt & operator&=(T v)
AtomicInt & operator-=(T delta)
static void MemoryBarrier()
AtomicInt & operator++()
These define the preincrement (i.e. –value) operators.
AtomicInt & operator=(const AtomicInt< T > &val)