SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWTAtomic< T * > Class Template Reference

Atomically manipulates a pointer 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
 
T * fetchAndAdd (ptrdiff_t val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
T * fetchAndAdd (ptrdiff_t val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
T * fetchAndSub (ptrdiff_t val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
T * fetchAndSub (ptrdiff_t val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 
T * load (RWAtomicMemoryOrder order=rw_mem_order_seq_cst) const
 
T * load (RWAtomicMemoryOrder order=rw_mem_order_seq_cst) const volatile
 
 operator T* () const
 
 operator T* () const volatile
 
T * operator++ ()
 
T * operator++ () volatile
 
T * operator++ (int)
 
T * operator++ (int) volatile
 
T * operator+= (ptrdiff_t val)
 
T * operator+= (ptrdiff_t val) volatile
 
T * operator-- ()
 
T * operator-- () volatile
 
T * operator-- (int)
 
T * operator-- (int) volatile
 
T * operator-= (ptrdiff_t val)
 
T * operator-= (ptrdiff_t val) volatile
 
T * operator= (T *val)
 
T * 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
 
T * swap (T *val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst)
 
T * swap (T *val, RWAtomicMemoryOrder order=rw_mem_order_seq_cst) volatile
 

Detailed Description

template<typename T>
class RWTAtomic< T * >

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

Example
RWTAtomic<char*> a = RW_ATOMIC_INIT(0);
char* prev = a.swap(new char('a'));
Atomically manipulates an integral type.
Definition atomic.h:127
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.

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 ( ptrdiff_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 ( ptrdiff_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;

◆ fetchAndSub() [1/2]

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

◆ 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/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+= ( ptrdiff_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+= ( ptrdiff_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-= ( ptrdiff_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-= ( ptrdiff_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);

◆ 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;

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