SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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++ ()
 
operator++ () volatile
 
operator++ (int)
 
operator++ (int) volatile
 
operator+= (T val)
 
operator+= (T val) volatile
 
operator-- ()
 
operator-- () volatile
 
operator-- (int)
 
operator-- (int) 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 Symbols

(Note that these are not member symbols.)

#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:

  • char
  • signed char
  • unsigned char
  • short
  • unsigned short
  • int
  • unsigned int
  • long
  • unsigned long
  • long long
  • unsigned long long
  • wchar_t
Example
int prev = a.swap(5);
Atomically manipulates an integral type.
Definition atomic.h:127
#define RW_ATOMIC_INIT(val)
Definition atomic.h:77
T swap(T val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
Definition atomic.h:337
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

◆ compareAndSwap() [1/2]

template<typename T >
bool RWTAtomic< T >::compareAndSwap ( T & expected,
T 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;
}

◆ compareAndSwap() [2/2]

template<typename T >
bool RWTAtomic< T >::compareAndSwap ( T & expected,
T 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;
}

◆ fetchAndAdd() [1/2]

template<typename T >
T RWTAtomic< T >::fetchAndAdd ( T 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;

◆ fetchAndAdd() [2/2]

template<typename T >
T RWTAtomic< T >::fetchAndAdd ( T 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;

◆ fetchAndAnd() [1/2]

template<typename T >
T RWTAtomic< T >::fetchAndAnd ( T 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;

◆ fetchAndAnd() [2/2]

template<typename T >
T RWTAtomic< T >::fetchAndAnd ( T 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;

◆ fetchAndOr() [1/2]

template<typename T >
T RWTAtomic< T >::fetchAndOr ( T 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;

◆ fetchAndOr() [2/2]

template<typename T >
T RWTAtomic< T >::fetchAndOr ( T 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;

◆ fetchAndSub() [1/2]

template<typename T >
T RWTAtomic< T >::fetchAndSub ( T 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;

◆ fetchAndSub() [2/2]

template<typename T >
T RWTAtomic< T >::fetchAndSub ( T 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;

◆ fetchAndXor() [1/2]

template<typename T >
T RWTAtomic< T >::fetchAndXor ( T 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;

◆ fetchAndXor() [2/2]

template<typename T >
T RWTAtomic< T >::fetchAndXor ( T 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;

◆ load() [1/2]

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.

◆ load() [2/2]

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.

◆ operator T() [1/2]

template<typename T >
RWTAtomic< T >::operator T ( ) const
inline

Returns the current value of self.

This function is equivalent to:

self.load();

◆ operator T() [2/2]

template<typename T >
RWTAtomic< T >::operator T ( ) const volatile
inline

Returns the current value of self.

This function is equivalent to:

self.load();

◆ operator&=() [1/2]

template<typename T >
T RWTAtomic< T >::operator&= ( T 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.

◆ operator&=() [2/2]

template<typename T >
T RWTAtomic< T >::operator&= ( T 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.

◆ operator++() [1/4]

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.

◆ operator++() [2/4]

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.

◆ operator++() [3/4]

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.

◆ operator++() [4/4]

template<typename T >
T RWTAtomic< T >::operator++ ( int ) volatile
inline

Increments self by 1. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.

◆ operator+=() [1/2]

template<typename T >
T RWTAtomic< T >::operator+= ( T val)
inline

Adds val to self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.

◆ operator+=() [2/2]

template<typename T >
T RWTAtomic< T >::operator+= ( T val) volatile
inline

Adds val to self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.

◆ operator--() [1/4]

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.

◆ operator--() [2/4]

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.

◆ operator--() [3/4]

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.

◆ operator--() [4/4]

template<typename T >
T RWTAtomic< T >::operator-- ( int ) volatile
inline

Decrements self by 1. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.

◆ operator-=() [1/2]

template<typename T >
T RWTAtomic< T >::operator-= ( T val)
inline

Subtracts val from self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.

◆ operator-=() [2/2]

template<typename T >
T RWTAtomic< T >::operator-= ( T val) volatile
inline

Subtracts val from self. Returns the new value.

Note
This function assumes rw_mem_order_seq_cst semantics.

◆ operator=() [1/2]

template<typename T >
T RWTAtomic< T >::operator= ( T val)
inline

Assigns val to self.

This function is equivalent to:

self.store(val);

◆ operator=() [2/2]

template<typename T >
T RWTAtomic< T >::operator= ( T val) volatile
inline

Assigns val to self.

This function is equivalent to:

self.store(val);

◆ operator^=() [1/2]

template<typename T >
T RWTAtomic< T >::operator^= ( T 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.

◆ operator^=() [2/2]

template<typename T >
T RWTAtomic< T >::operator^= ( T 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.

◆ operator|=() [1/2]

template<typename T >
T RWTAtomic< T >::operator|= ( T 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.

◆ operator|=() [2/2]

template<typename T >
T RWTAtomic< T >::operator|= ( T 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.

◆ store() [1/2]

template<typename T >
void RWTAtomic< T >::store ( T 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.

◆ store() [2/2]

template<typename T >
void RWTAtomic< T >::store ( T 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.

◆ swap() [1/2]

template<typename T >
T RWTAtomic< T >::swap ( T 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;

◆ swap() [2/2]

template<typename T >
T RWTAtomic< T >::swap ( T 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 Symbol Documentation

◆ RW_ATOMIC_INIT

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

Initializes an RWTAtomic<T> to the value val.

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