libcommonc++  0.7
AtomicCounter Class Reference

An integer counter whose value is modified in an atomic fashion. More...

#include <AtomicCounter.h++>

Public Member Functions

 AtomicCounter (int32_t value=0)
 Construct a new AtomicCounter with the given initial value. More...
 
 ~AtomicCounter ()
 Destructor. More...
 
 AtomicCounter (const AtomicCounter &other)
 Copy constructor. More...
 
AtomicCounteroperator= (const AtomicCounter &other)
 Assignment operator. More...
 
int32_t operator++ ()
 Increment the counter (prefix). More...
 
int32_t operator++ (int)
 Increment the counter (postfix). More...
 
int32_t operator-- ()
 Decrement the counter (prefix). More...
 
int32_t operator-- (int)
 Decrement the counter (postfix). More...
 
int32_t operator+= (int32_t delta)
 Add a value to the counter. More...
 
int32_t operator-= (int32_t delta)
 Subtract a value from the counter. More...
 
int32_t operator+ (int32_t delta) const
 Compute the sum of the counter and a value. More...
 
int32_t operator- (int32_t delta) const
 Compute the difference between the counter and a value. More...
 
int32_t operator= (int32_t value)
 Assign a new value to the counter. More...
 
int32_t set (int32_t value)
 Assign a new value to the counter, returning the new value. More...
 
int32_t swap (int32_t value)
 Assign a new value to the counter, returning the previous value. More...
 
int32_t testAndSet (int32_t value, int32_t comparand)
 Test and set the counter value. More...
 
int32_t get () const
 Get the current value of the counter. More...
 
 operator int32_t () const
 Cast operator. More...
 

Detailed Description

An integer counter whose value is modified in an atomic fashion.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ AtomicCounter() [1/2]

AtomicCounter ( int32_t  value = 0)

Construct a new AtomicCounter with the given initial value.

Parameters
valueThe initial value.

◆ ~AtomicCounter()

Destructor.

◆ AtomicCounter() [2/2]

AtomicCounter ( const AtomicCounter other)

Copy constructor.

Member Function Documentation

◆ get()

int32_t get ( ) const

Get the current value of the counter.

◆ operator int32_t()

operator int32_t ( ) const
inline

Cast operator.

◆ operator+()

int32_t operator+ ( int32_t  delta) const

Compute the sum of the counter and a value.

◆ operator++() [1/2]

int32_t operator++ ( )

Increment the counter (prefix).

◆ operator++() [2/2]

int32_t operator++ ( int  )

Increment the counter (postfix).

◆ operator+=()

int32_t operator+= ( int32_t  delta)

Add a value to the counter.

◆ operator-()

int32_t operator- ( int32_t  delta) const

Compute the difference between the counter and a value.

◆ operator--() [1/2]

int32_t operator-- ( )

Decrement the counter (prefix).

◆ operator--() [2/2]

int32_t operator-- ( int  )

Decrement the counter (postfix).

◆ operator-=()

int32_t operator-= ( int32_t  delta)

Subtract a value from the counter.

◆ operator=() [1/2]

AtomicCounter & operator= ( const AtomicCounter other)

Assignment operator.

◆ operator=() [2/2]

int32_t operator= ( int32_t  value)

Assign a new value to the counter.

◆ set()

int32_t set ( int32_t  value)

Assign a new value to the counter, returning the new value.

◆ swap()

int32_t swap ( int32_t  value)

Assign a new value to the counter, returning the previous value.

◆ testAndSet()

int32_t testAndSet ( int32_t  value,
int32_t  comparand 
)

Test and set the counter value.

Parameters
comparandThe value to compare the counter to.
valueThe value to set the counter to, if the current value is equal to the comparand.
Returns
The original (and possibly unchanged) value of the counter.

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