SourcePro® API Reference Guide

 
List of all members | Public Member Functions
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++ (int)
 
T * operator++ (int) volatile
 
T * operator++ ()
 
T * operator++ () volatile
 
T * operator+= (ptrdiff_t val)
 
T * operator+= (ptrdiff_t val) volatile
 
T * operator-- (int)
 
T * operator-- (int) volatile
 
T * operator-- ()
 
T * operator-- () 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'));
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

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;
}
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;
}
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;
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;
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;
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;
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++ ( 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+= ( ptrdiff_t  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+= ( ptrdiff_t  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-= ( ptrdiff_t  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-= ( ptrdiff_t  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= ( T *  val)
inline

Assigns val to self.

This function is equivalent to:

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

Assigns val to self.

This function is equivalent to:

self.store(val);
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.
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.
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;
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 © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.