Click
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
atomic_uint32_t Class Reference

A 32-bit integer with support for atomic operations. More...

#include <atomic.hh>

Public Member Functions

uint32_t value () const
 Return the value.
 
uint32_t nonatomic_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 nonatomic_inc ()
 Increment the value.
 
void operator++ ()
 Atomically increment the value.
 
void operator++ (int)
 Atomically increment the value.
 
void nonatomic_dec ()
 Decrement 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.
 
bool nonatomic_dec_and_test ()
 Decrement the value, returning true if the new value is 0.
 
uint32_t compare_swap (uint32_t expected, uint32_t desired) CLICK_BUILTINS_DEPRECATED
 
bool compare_and_swap (uint32_t expected, uint32_t desired) CLICK_BUILTINS_NONDEPRECATED
 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) 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 ()
 

Detailed Description

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).

Member Function Documentation

◆ value()

uint32_t atomic_uint32_t::value ( ) const
inline

Return the value.

◆ nonatomic_value()

uint32_t atomic_uint32_t::nonatomic_value ( ) const
inline

Return the value.

◆ operator uint32_t()

atomic_uint32_t::operator uint32_t ( ) const
inline

Return the value.

◆ operator=()

atomic_uint32_t & atomic_uint32_t::operator= ( uint32_t  x)
inline

Set the value to x.

◆ operator+=()

atomic_uint32_t & atomic_uint32_t::operator+= ( int32_t  delta)
inline

Atomically add delta to the value.

◆ operator-=()

atomic_uint32_t & atomic_uint32_t::operator-= ( int32_t  delta)
inline

Atomically subtract delta from the value.

◆ operator|=()

atomic_uint32_t & atomic_uint32_t::operator|= ( uint32_t  mask)
inline

Atomically bitwise-or the value with mask.

◆ operator&=()

atomic_uint32_t & atomic_uint32_t::operator&= ( uint32_t  mask)
inline

Atomically bitwise-and the value with mask.

◆ nonatomic_inc()

void atomic_uint32_t::nonatomic_inc ( )
inline

Increment the value.

◆ operator++() [1/2]

void atomic_uint32_t::operator++ ( )
inline

Atomically increment the value.

◆ operator++() [2/2]

void atomic_uint32_t::operator++ ( int  )
inline

Atomically increment the value.

◆ nonatomic_dec()

void atomic_uint32_t::nonatomic_dec ( )
inline

Decrement the value.

◆ operator--() [1/2]

void atomic_uint32_t::operator-- ( )
inline

Atomically decrement the value.

◆ operator--() [2/2]

void atomic_uint32_t::operator-- ( int  )
inline

Atomically decrement the value.

◆ swap() [1/2]

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;
uint32_t value() const
Return the value.
Definition atomic.hh:179

Also acts as a memory barrier.

◆ fetch_and_add()

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;

◆ dec_and_test() [1/2]

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;

◆ nonatomic_dec_and_test()

bool atomic_uint32_t::nonatomic_dec_and_test ( )
inline

Decrement the value, returning true if the new value is 0.

Behaves like this, but in one atomic step:

--*this;
return value() == 0;

◆ compare_and_swap() [1/2]

bool atomic_uint32_t::compare_and_swap ( uint32_t  expected,
uint32_t  desired 
)
inline

Perform a compare-and-swap operation.

Parameters
expectedtest value
desirednew 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
expectedtest value
desirednew 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.

◆ swap() [2/2]

uint32_t atomic_uint32_t::swap ( volatile uint32_t &  x,
uint32_t  desired 
)
inlinestatic

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.

◆ inc()

void atomic_uint32_t::inc ( volatile uint32_t &  x)
inlinestatic

Atomically increment value x.

◆ dec_and_test() [2/2]

bool atomic_uint32_t::dec_and_test ( volatile uint32_t &  x)
inlinestatic

Atomically decrement x, returning true if the new x is 0.

Behaves like this, but in one atomic step:

--x;
return x == 0;

◆ compare_and_swap() [2/2]

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
xvalue
expectedtest value
desirednew 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
xvalue
expectedtest value
desirednew 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.


The documentation for this class was generated from the following file: