Zero  0.1.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lintel::Atomic< T > Class Template Reference

An atomic counter that avoids using locks. More...

#include <AtomicCounter.hpp>

Public Member Functions

 Atomic ()
 
 Atomic (T counter)
 
T incThenFetch ()
 
T decThenFetch ()
 
T addThenFetch (T amount)
 
bool isZero () const
 
 operator T () const
 
T load () const
 
void store (T t)
 
T operator= (T amount)
 Assignement. More...
 
T exchange (T t)
 
bool compare_exchange_strong (T *expected, T desired)
 
T fetch_add (T amount)
 
T fetch_sub (T amount)
 
T fetch_or (T amount)
 
T fetch_and (T amount)
 
T fetch_xor (T amount)
 
T operator+= (T amount)
 
T operator-= (T amount)
 
T operator|= (T amount)
 
T operator &= (T amount)
 
T operator^= (T amount)
 
T operator++ (int)
 
T operator-- (int)
 
T operator++ ()
 
T operator-- ()
 

Private Member Functions

 Atomic (const Atomic &)
 Copy construction is forbidden. More...
 
Atomicoperator= (const Atomic &)
 Copy assignment is forbidden. More...
 

Private Attributes

T counter
 

Detailed Description

template<class T>
class lintel::Atomic< T >

An atomic counter that avoids using locks.

Encapsulates an atomic counter. Be wary when using it so as to not inadvertently introduce a race–the value may change at any time outside of the defined operations.

If you really need the current value, then fetchThenAdd(0). Beware that the returned value may immediatly become out of date!

Constructor & Destructor Documentation

§ Atomic() [1/3]

template<class T>
lintel::Atomic< T >::Atomic ( )
inline

§ Atomic() [2/3]

template<class T>
lintel::Atomic< T >::Atomic ( T  counter)
inlineexplicit

§ Atomic() [3/3]

template<class T>
lintel::Atomic< T >::Atomic ( const Atomic< T > &  )
private

Copy construction is forbidden.

Member Function Documentation

§ addThenFetch()

template<class T>
T lintel::Atomic< T >::addThenFetch ( T  amount)
inline

Adds amount to the counter and then returns the value C11/C++11 have no such function. Use operator += instead

§ compare_exchange_strong()

template<class T>
bool lintel::Atomic< T >::compare_exchange_strong ( T expected,
T  desired 
)
inline

§ decThenFetch()

template<class T>
T lintel::Atomic< T >::decThenFetch ( )
inline

Decrements the counter and then returns the value C11/C++11 have no such function. Use prefix operator--() instead

§ exchange()

template<class T>
T lintel::Atomic< T >::exchange ( T  t)
inline

§ fetch_add()

template<class T>
T lintel::Atomic< T >::fetch_add ( T  amount)
inline

§ fetch_and()

template<class T>
T lintel::Atomic< T >::fetch_and ( T  amount)
inline

§ fetch_or()

template<class T>
T lintel::Atomic< T >::fetch_or ( T  amount)
inline

§ fetch_sub()

template<class T>
T lintel::Atomic< T >::fetch_sub ( T  amount)
inline

§ fetch_xor()

template<class T>
T lintel::Atomic< T >::fetch_xor ( T  amount)
inline

§ incThenFetch()

template<class T>
T lintel::Atomic< T >::incThenFetch ( )
inline

Increments the counter and then returns the value C11/C++11 have no such function. Use prefix operator++() instead

§ isZero()

template<class T>
bool lintel::Atomic< T >::isZero ( ) const
inline

Returns true if the counter is zero C11/C++11 have no such function. Use operator T() instead

§ load()

template<class T>
T lintel::Atomic< T >::load ( ) const
inline

§ operator &=()

template<class T>
T lintel::Atomic< T >::operator&= ( T  amount)
inline

§ operator T()

template<class T>
lintel::Atomic< T >::operator T ( ) const
inline

§ operator++() [1/2]

template<class T>
T lintel::Atomic< T >::operator++ ( int  )
inline

§ operator++() [2/2]

template<class T>
T lintel::Atomic< T >::operator++ ( )
inline

§ operator+=()

template<class T>
T lintel::Atomic< T >::operator+= ( T  amount)
inline

§ operator--() [1/2]

template<class T>
T lintel::Atomic< T >::operator-- ( int  )
inline

§ operator--() [2/2]

template<class T>
T lintel::Atomic< T >::operator-- ( )
inline

§ operator-=()

template<class T>
T lintel::Atomic< T >::operator-= ( T  amount)
inline

§ operator=() [1/2]

template<class T>
T lintel::Atomic< T >::operator= ( T  amount)
inline

Assignement.

§ operator=() [2/2]

template<class T>
Atomic& lintel::Atomic< T >::operator= ( const Atomic< T > &  )
private

Copy assignment is forbidden.

§ operator^=()

template<class T>
T lintel::Atomic< T >::operator^= ( T  amount)
inline

§ operator|=()

template<class T>
T lintel::Atomic< T >::operator|= ( T  amount)
inline

§ store()

template<class T>
void lintel::Atomic< T >::store ( T  t)
inline

Member Data Documentation

§ counter

template<class T>
T lintel::Atomic< T >::counter
private

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