Equalizer  1.2.1
Public Member Functions | Static Public Member Functions
co::base::Atomic< T > Class Template Reference

A variable with atomic semantics and standalone atomic operations. More...

#include <atomic.h>

List of all members.

Public Member Functions

 Atomic (const T v=0)
 Construct a new atomic variable with an initial value.
 Atomic (const Atomic< T > &v)
 Construct a copy of an atomic variable.
 operator T (void) const
void operator= (const T v)
 Assign a new value.
void operator= (const Atomic< T > &v)
 Assign a new value.
operator+= (T v)
 Atomically add a value and return the new value.
operator-= (T v)
 Atomically substract a value and return the new value.
operator++ (void)
 Atomically increment by one and return the new value.
operator-- (void)
 Atomically decrement by one and return the new value.
operator++ (int)
 Atomically increment by one and return the old value.
operator-- (int)
 Atomically decrement by one and return the old value.
bool operator== (const Atomic< T > &rhs) const
bool operator!= (const Atomic< T > &rhs) const
bool compareAndSwap (const T expected, const T newValue)
 Perform a compare-and-swap atomic operation.

Static Public Member Functions

static COBASE_API T getAndAdd (T &value, const T increment)
static COBASE_API T getAndSub (T &value, const T increment)
static T addAndGet (T &value, const T increment)
static T subAndGet (T &value, const T increment)
static COBASE_API T incAndGet (T &value)
static COBASE_API T decAndGet (T &value)
static COBASE_API bool compareAndSwap (T *value, const T expected, const T newValue)
 Perform a compare-and-swap atomic operation.

Detailed Description

template<class T>
class co::base::Atomic< T >

A variable with atomic semantics and standalone atomic operations.

Atomic variables can be modified safely from multiple threads concurrently. They are useful to implement lock-free algorithms.

For implementation reasons, only signed atomic variables are supported, of which only int32_t is implemented right now.

Definition at line 58 of file atomic.h.


Constructor & Destructor Documentation

template<class T>
co::base::Atomic< T >::Atomic ( const T  v = 0) [explicit]

Construct a new atomic variable with an initial value.

Version:
1.0

Definition at line 194 of file atomic.h.

template<class T>
co::base::Atomic< T >::Atomic ( const Atomic< T > &  v)

Construct a copy of an atomic variable.

Not thread-safe!

Version:
1.0

Definition at line 197 of file atomic.h.


Member Function Documentation

template<class T>
T co::base::Atomic< T >::addAndGet ( T &  value,
const T  increment 
) [static]
Returns:
the new value after adding the given increment.

Definition at line 151 of file atomic.h.

template<class T>
bool co::base::Atomic< T >::compareAndSwap ( T *  value,
const T  expected,
const T  newValue 
) [static]

Perform a compare-and-swap atomic operation.

Definition at line 172 of file atomic.h.

Referenced by co::base::SpinLock::trySet(), co::base::SpinLock::trySetRead(), and co::base::SpinLock::unsetRead().

+ Here is the caller graph for this function:

template<class T>
bool co::base::Atomic< T >::compareAndSwap ( const T  expected,
const T  newValue 
)

Perform a compare-and-swap atomic operation.

Atomically replaces the value and return true if the value matched the expected.

Returns:
true if the new value was set, false otherwise
Version:
1.1.2

Definition at line 260 of file atomic.h.

template<class T>
T co::base::Atomic< T >::decAndGet ( T &  value) [static]
Returns:
the new value after decrementing the value.

Definition at line 166 of file atomic.h.

template<class T>
T co::base::Atomic< T >::getAndAdd ( T &  value,
const T  increment 
) [static]
Returns:
the old value, then add the given increment.

Definition at line 141 of file atomic.h.

template<class T>
T co::base::Atomic< T >::getAndSub ( T &  value,
const T  increment 
) [static]
Returns:
the old value, then substract the increment.

Definition at line 146 of file atomic.h.

template<class T>
T co::base::Atomic< T >::incAndGet ( T &  value) [static]
Returns:
the new value after incrementing the value.

Definition at line 161 of file atomic.h.

template<class T >
co::base::Atomic< T >::operator T ( void  ) const
Returns:
the current value
Version:
1.0

Definition at line 200 of file atomic.h.

template<class T>
bool co::base::Atomic< T >::operator!= ( const Atomic< T > &  rhs) const
Returns:
true if the variable has not the given value.
Version:
1.1.2

Definition at line 253 of file atomic.h.

References co::base::memoryBarrier().

+ Here is the call graph for this function:

template<class T >
T co::base::Atomic< T >::operator++ ( void  )

Atomically increment by one and return the new value.

Version:
1.0

Definition at line 227 of file atomic.h.

template<class T >
T co::base::Atomic< T >::operator++ ( int  )

Atomically increment by one and return the old value.

Version:
1.0

Definition at line 237 of file atomic.h.

template<class T>
T co::base::Atomic< T >::operator+= ( v)

Atomically add a value and return the new value.

Version:
1.0

Definition at line 217 of file atomic.h.

template<class T >
T co::base::Atomic< T >::operator-- ( void  )

Atomically decrement by one and return the new value.

Version:
1.0

Definition at line 232 of file atomic.h.

template<class T >
T co::base::Atomic< T >::operator-- ( int  )

Atomically decrement by one and return the old value.

Version:
1.0

Definition at line 242 of file atomic.h.

template<class T>
T co::base::Atomic< T >::operator-= ( v)

Atomically substract a value and return the new value.

Version:
1.0

Definition at line 222 of file atomic.h.

template<class T>
void co::base::Atomic< T >::operator= ( const T  v)

Assign a new value.

Version:
1.0

Definition at line 205 of file atomic.h.

References co::base::memoryBarrier().

+ Here is the call graph for this function:

template<class T>
void co::base::Atomic< T >::operator= ( const Atomic< T > &  v)

Assign a new value.

Not thread-safe!

Version:
1.0

Definition at line 211 of file atomic.h.

References co::base::memoryBarrier().

+ Here is the call graph for this function:

template<class T>
bool co::base::Atomic< T >::operator== ( const Atomic< T > &  rhs) const
Returns:
true if the variable has the given value.
Version:
1.1.2

Definition at line 247 of file atomic.h.

References co::base::memoryBarrier().

+ Here is the call graph for this function:

template<class T>
T co::base::Atomic< T >::subAndGet ( T &  value,
const T  increment 
) [static]
Returns:
the new value after substracting the increment.

Definition at line 156 of file atomic.h.


The documentation for this class was generated from the following file:
Generated on Fri Jun 8 2012 15:44:34 for Equalizer 1.2.1 by  doxygen 1.8.0