SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Related Functions
RWTAtomic< T > Class Template Reference

Atomically manipulates an integral type. More...

#include <rw/tools/atomic.h>

Public Member Functions

bool compareAndSwap (T &expected, T desired, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
bool compareAndSwap (T &expected, T desired, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
fetchAndAdd (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
fetchAndAdd (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
fetchAndAnd (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
fetchAndAnd (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
fetchAndOr (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
fetchAndOr (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
fetchAndSub (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
fetchAndSub (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
fetchAndXor (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
fetchAndXor (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
load (RWAtomicMemoryOrder order=rw_mem_order_seq_cst) const
 
load (RWAtomicMemoryOrder order=rw_mem_order_seq_cst) const volatile
 
 operator T () const
 
 operator T () const volatile
 
operator&= (T val)
 
operator&= (T val) volatile
 
operator++ (int)
 
operator++ (int) volatile
 
operator++ ()
 
operator++ () volatile
 
operator+= (T val)
 
operator+= (T val) volatile
 
operator-- (int)
 
operator-- (int) volatile
 
operator-- ()
 
operator-- () volatile
 
operator-= (T val)
 
operator-= (T val) volatile
 
operator= (T val)
 
operator= (T val) volatile
 
operator^= (T val)
 
operator^= (T val) volatile
 
operator|= (T val)
 
operator|= (T val) volatile
 
void store (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
void store (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
swap (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
swap (T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 

Related Functions

(Note that these are not member functions.)

#define RW_ATOMIC_INIT(val)
 

Detailed Description

template<typename T>
class RWTAtomic< T >

RWTAtomic provides atomic manipulation of an underlying integral type T. All operations performed on an RWTAtomic instance are atomic.

RWTAtomic is limited to the following integral types and their associated typedefs:

Example
int prev = a.swap(5);
Note
While copy construction and assignment are not prohibited, these operations are not performed in an atomic manner, and may result in undefined behavior. These operations may be prohibited in a future release and should be avoided.
64-bit integral types are not supported in 32-bit builds on AIX.

Member Function Documentation

template<typename T>
bool RWTAtomic< T >::compareAndSwap ( T &  expected,
desired,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
)
inline

Compares expected to self. If expected is equal to self, desired is assigned to self and true is returned. If expected is not equal to self, self is assigned to expected and false is returned.

This function is equivalent to:

if (self == expected) {
self = desired;
return true;
}
else {
expected = self;
return false;
}
template<typename T>
bool RWTAtomic< T >::compareAndSwap ( T &  expected,
desired,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
) volatile
inline

Compares expected to self. If expected is equal to self, desired is assigned to self and true is returned. If expected is not equal to self, self is assigned to expected and false is returned.

This function is equivalent to:

if (self == expected) {
self = desired;
return true;
}
else {
expected = self;
return false;
}
template<typename T>
T RWTAtomic< T >::fetchAndAdd ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
)
inline

Adds val to self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self += val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndAdd ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
) volatile
inline

Adds val to self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self += val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndAnd ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
)
inline

Performs a bitwise AND between val and self, storing the result in self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self &= val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndAnd ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
) volatile
inline

Performs a bitwise AND between val and self, storing the result in self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self &= val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndOr ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
)
inline

Performs a bitwise OR between val and self, storing the result in self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self |= val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndOr ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
) volatile
inline

Performs a bitwise OR between val and self, storing the result in self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self |= val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndSub ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
)
inline

Subtracts val from self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self -= val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndSub ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
) volatile
inline

Subtracts val from self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self -= val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndXor ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
)
inline

Performs a bitwise XOR between val and self, storing the result in self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self ^= val;
return prev;
template<typename T>
T RWTAtomic< T >::fetchAndXor ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
) volatile
inline

Performs a bitwise XOR between val and self, storing the result in self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self ^= val;
return prev;
template<typename T>
T RWTAtomic< T >::load ( RWAtomicMemoryOrder  order = rw_mem_order_seq_cst) const
inline

Returns the current value of self.

Note
order values of rw_mem_order_release and rw_mem_order_acq_rel are not supported and will result in undefined behavior.
template<typename T>
T RWTAtomic< T >::load ( RWAtomicMemoryOrder  order = rw_mem_order_seq_cst) const volatile
inline

Returns the current value of self.

Note
order values of rw_mem_order_release and rw_mem_order_acq_rel are not supported and will result in undefined behavior.
template<typename T>
RWTAtomic< T >::operator T ( ) const
inline

Returns the current value of self.

This function is equivalent to:

self.load();
template<typename T>
RWTAtomic< T >::operator T ( ) const volatile
inline

Returns the current value of self.

This function is equivalent to:

self.load();
template<typename T>
T RWTAtomic< T >::operator&= ( val)
inline

Performs a bitwise AND between val and self, storing the result in self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator&= ( val) volatile
inline

Performs a bitwise AND between val and self, storing the result in self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator++ ( int  )
inline

Increments self by 1. Returns the previous value of self.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator++ ( int  ) volatile
inline

Increments self by 1. Returns the previous value of self.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator++ ( )
inline

Increments self by 1. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator++ ( ) volatile
inline

Increments self by 1. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator+= ( val)
inline

Adds val to self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator+= ( val) volatile
inline

Adds val to self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator-- ( int  )
inline

Decrements self by 1. Returns the previous value of self.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator-- ( int  ) volatile
inline

Decrements self by 1. Returns the previous value of self.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator-- ( )
inline

Decrements self by 1. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator-- ( ) volatile
inline

Decrements self by 1. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator-= ( val)
inline

Subtracts val from self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator-= ( val) volatile
inline

Subtracts val from self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator= ( val)
inline

Assigns val to self.

This function is equivalent to:

self.store(val);
template<typename T>
T RWTAtomic< T >::operator= ( val) volatile
inline

Assigns val to self.

This function is equivalent to:

self.store(val);
template<typename T>
T RWTAtomic< T >::operator^= ( val)
inline

Performs a bitwise XOR between val and self, storing the result in self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator^= ( val) volatile
inline

Performs a bitwise XOR between val and self, storing the result in self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator|= ( val)
inline

Performs a bitwise OR between val and self, storing the result in self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
T RWTAtomic< T >::operator|= ( val) volatile
inline

Performs a bitwise OR between val and self, storing the result in self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.
template<typename T>
void RWTAtomic< T >::store ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
)
inline

Assigns val to self.

Note
order values of rw_mem_order_consume, rw_mem_order_acquire and rw_mem_order_acq_rel are not supported and will result in undefined behavior.
template<typename T>
void RWTAtomic< T >::store ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
) volatile
inline

Assigns val to self.

Note
order values of rw_mem_order_consume, rw_mem_order_acquire and rw_mem_order_acq_rel are not supported and will result in undefined behavior.
template<typename T>
T RWTAtomic< T >::swap ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
)
inline

Assigns val to self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self = val;
return prev;
template<typename T>
T RWTAtomic< T >::swap ( val,
RWAtomicMemoryOrder  order = rw_mem_order_seq_cst 
) volatile
inline

Assigns val to self. Returns the previous value of self.

This function is equivalent to:

T prev = self;
self = val;
return prev;

Friends And Related Function Documentation

template<typename T>
#define RW_ATOMIC_INIT (   val)
related

Initializes an RWTAtomic<T> to the value val.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.