#include <atomic.hh>
Public Member Functions | |
| uint32_t | value () const |
| Return the value. | |
| operator uint32_t () const | |
| Return the value. | |
| atomic_uint32_t & | operator= (uint32_t x) |
| Set the value to x. | |
| atomic_uint32_t & | operator+= (int32_t delta) |
| Atomically add delta to the value. | |
| atomic_uint32_t & | operator-= (int32_t delta) |
| Atomically subtract delta from the value. | |
| atomic_uint32_t & | operator|= (uint32_t mask) |
| Atomically bitwise-or the value with mask. | |
| atomic_uint32_t & | operator &= (uint32_t mask) |
| Atomically bitwise-and the value with mask. | |
| void | operator++ () |
| Atomically increment the value. | |
| void | operator++ (int) |
| Atomically increment the value. | |
| void | operator-- () |
| Atomically decrement the value. | |
| void | operator-- (int) |
| Atomically decrement the value. | |
| uint32_t | swap (uint32_t desired) |
| Atomically assign the value to desired, returning the old value. | |
| uint32_t | fetch_and_add (uint32_t delta) |
| Atomically add delta to the value, returning the old value. | |
| bool | dec_and_test () |
| Atomically decrement the value, returning true if the new value is 0. | |
| uint32_t | compare_swap (uint32_t expected, uint32_t desired) |
| Perform a compare-and-swap operation. | |
| bool | compare_and_swap (uint32_t expected, uint32_t desired) |
| Perform a compare-and-swap operation. | |
Static Public Member Functions | |
| static uint32_t | swap (volatile uint32_t &x, uint32_t desired) |
| Atomically assign the value to desired, returning the old value. | |
| static void | inc (volatile uint32_t &x) |
| Atomically increment value x. | |
| static bool | dec_and_test (volatile uint32_t &x) |
| Atomically decrement x, returning true if the new x is 0. | |
| static uint32_t | compare_swap (volatile uint32_t &x, uint32_t expected, uint32_t desired) |
| Perform a compare-and-swap operation. | |
| static bool | compare_and_swap (volatile uint32_t &x, uint32_t expected, uint32_t desired) |
| Perform a compare-and-swap operation. | |
The atomic_uint32_t class represents a 32-bit integer, with support for atomic operations. The +=, -=, &=, |=, ++, and -- operations are implemented using atomic instructions. There are also atomic swap(), fetch_and_add(), dec_and_test(), and compare_swap() operations.
Because of some issues with compiler implementations, atomic_uint32_t has no explicit constructor; to set an atomic_uint32_t to a value, use operator=.
The atomic_uint32_t only provides true atomic semantics when that has been implemented. It has been implemented in the Linux kernel, and at userlevel (when --enable-multithread has been defined) for x86 machines. In other situations, it's not truly atomic (because it doesn't need to be).
| uint32_t atomic_uint32_t::value | ( | ) | const [inline] |
Return the value.
| atomic_uint32_t::operator uint32_t | ( | ) | const [inline] |
Return the value.
| atomic_uint32_t & atomic_uint32_t::operator= | ( | uint32_t | x | ) | [inline] |
Set the value to x.
| atomic_uint32_t & atomic_uint32_t::operator+= | ( | int32_t | delta | ) | [inline] |
Atomically add delta to the value.
| atomic_uint32_t & atomic_uint32_t::operator-= | ( | int32_t | delta | ) | [inline] |
Atomically subtract delta from the value.
| atomic_uint32_t & atomic_uint32_t::operator|= | ( | uint32_t | mask | ) | [inline] |
Atomically bitwise-or the value with mask.
| atomic_uint32_t & atomic_uint32_t::operator &= | ( | uint32_t | mask | ) | [inline] |
Atomically bitwise-and the value with mask.
| void atomic_uint32_t::operator++ | ( | ) | [inline] |
Atomically increment the value.
| void atomic_uint32_t::operator++ | ( | int | ) | [inline] |
Atomically increment the value.
| void atomic_uint32_t::operator-- | ( | ) | [inline] |
Atomically decrement the value.
| void atomic_uint32_t::operator-- | ( | int | ) | [inline] |
Atomically decrement the value.
| uint32_t atomic_uint32_t::swap | ( | uint32_t | desired | ) | [inline] |
Atomically assign the value to desired, returning the old value.
Behaves like this, but in one atomic step:
uint32_t old_value = value(); *this = desired; return old_value;
Also acts as a memory barrier.
| uint32_t atomic_uint32_t::fetch_and_add | ( | uint32_t | delta | ) | [inline] |
Atomically add delta to the value, returning the old value.
Behaves like this, but in one atomic step:
uint32_t old_value = value(); *this += delta; return old_value;
| bool atomic_uint32_t::dec_and_test | ( | ) | [inline] |
Atomically decrement the value, returning true if the new value is 0.
Behaves like this, but in one atomic step:
--*this; return value() == 0;
| uint32_t atomic_uint32_t::compare_swap | ( | uint32_t | expected, | |
| uint32_t | desired | |||
| ) | [inline] |
Perform a compare-and-swap operation.
| expected | test value | |
| desired | new value |
uint32_t actual = value(); if (actual == expected) *this = desired; return actual;
Also acts as a memory barrier.
| bool atomic_uint32_t::compare_and_swap | ( | uint32_t | expected, | |
| uint32_t | desired | |||
| ) | [inline] |
Perform a compare-and-swap operation.
| expected | test value | |
| desired | new value |
uint32_t old_value = value(); if (old_value == expected) *this = desired; return old_value == expected;
Also acts as a memory barrier.
| uint32_t atomic_uint32_t::swap | ( | volatile uint32_t & | x, | |
| uint32_t | desired | |||
| ) | [inline, static] |
Atomically assign the value to desired, returning the old value.
Behaves like this, but in one atomic step:
uint32_t actual = x;
x = desired;
return actual;
Also acts as a memory barrier.
| void atomic_uint32_t::inc | ( | volatile uint32_t & | x | ) | [inline, static] |
Atomically increment value x.
| bool atomic_uint32_t::dec_and_test | ( | volatile uint32_t & | x | ) | [inline, static] |
Atomically decrement x, returning true if the new x is 0.
Behaves like this, but in one atomic step:
--x;
return x == 0;
| uint32_t atomic_uint32_t::compare_swap | ( | volatile uint32_t & | x, | |
| uint32_t | expected, | |||
| uint32_t | desired | |||
| ) | [inline, static] |
Perform a compare-and-swap operation.
| x | value | |
| expected | test value | |
| desired | new value |
uint32_t actual = x; if (x == expected) x = desired; return actual;
Also acts as a memory barrier.
| bool atomic_uint32_t::compare_and_swap | ( | volatile uint32_t & | x, | |
| uint32_t | expected, | |||
| uint32_t | desired | |||
| ) | [inline, static] |
Perform a compare-and-swap operation.
| x | value | |
| expected | test value | |
| desired | new value |
uint32_t old_value = x; if (x == expected) x = desired; return old_value == expected;
Also acts as a memory barrier.
1.5.6