|
| 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) CLICK_BUILTINS_DEPRECATED |
| |
| static bool | compare_and_swap (volatile uint32_t &x, uint32_t expected, uint32_t desired) CLICK_BUILTINS_NONDEPRECATED |
| | Perform a compare-and-swap operation.
|
| |
|
static bool | use_builtins () |
| |
A 32-bit integer with support for atomic operations.
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).
| bool atomic_uint32_t::compare_and_swap |
( |
uint32_t |
expected, |
|
|
uint32_t |
desired |
|
) |
| |
|
inline |
Perform a compare-and-swap operation.
- Parameters
-
| expected | test value |
| desired | new value |
- Returns
- The actual old value. If expected is returned, the value has been set to desired.
Behaves like this, but in one atomic step:
uint32_t actual =
value();
if (actual == expected)
*this = desired;
return actual;
Also acts as a memory barrier.
Perform a compare-and-swap operation.
- Parameters
-
| expected | test value |
| desired | new value |
- Returns
- True if the old value equaled expected (in which case the value was set to desired), false otherwise.
- Deprecated:
- Use compare_swap instead.
Behaves like this, but in one atomic step:
uint32_t old_value =
value();
if (old_value == expected)
*this = desired;
return old_value == expected;
Also acts as a memory barrier.
| bool atomic_uint32_t::compare_and_swap |
( |
volatile uint32_t & |
x, |
|
|
uint32_t |
expected, |
|
|
uint32_t |
desired |
|
) |
| |
|
inlinestatic |
Perform a compare-and-swap operation.
- Parameters
-
| x | value |
| expected | test value |
| desired | new value |
- Returns
- The actual old value. If it equaled expected, x has been set to desired.
Behaves like this, but in one atomic step:
uint32_t actual = x;
if (x == expected)
x = desired;
return actual;
Also acts as a memory barrier.
Perform a compare-and-swap operation.
- Parameters
-
| x | value |
| expected | test value |
| desired | new value |
- Returns
- True if the old x equaled expected (in which case x was set to desired), false otherwise.
- Deprecated:
- Use compare_swap instead.
Behaves like this, but in one atomic step:
uint32_t old_value = x;
if (x == expected)
x = desired;
return old_value == expected;
Also acts as a memory barrier.