This class implements a simple counter, whit atomic operations for use in a multithreaded environment. More...

#include <mn_atomic_counter.hpp>

+ Collaboration diagram for mn::atomic_counter:

Public Types

using value_type = int
 

Public Member Functions

 atomic_counter ()
 Construct a new atomic_counter and initializes it to zero. More...
 
 atomic_counter (const value_type &value)
 Construct a new atomic_counter and initializes it with the given value. More...
 
 atomic_counter (const atomic_counter &other)
 Construct a new atomic_counter from a other atomic_counter. More...
 
 operator value_type () const
 Converts the atomic_counter to value_type. More...
 
value_type value () const
 Get the value of the counter. More...
 
value_type operator++ ()
 Increments the counter. More...
 
value_type operator-- ()
 Decrements the counter. More...
 
value_type operator++ (int)
 Increments the counter. More...
 
value_type operator-- (int)
 Decrements the counter. More...
 
bool operator! () const
 If the counter zero? More...
 
atomic_counteroperator= (const atomic_counter &other)
 Assigns the value of another atomic_counter. More...
 
atomic_counteroperator= (const value_type &value)
 Assigns a value to the counter. More...
 

Private Attributes

_atomic< value_typem_atomicCount
 

Detailed Description

This class implements a simple counter, whit atomic operations for use in a multithreaded environment.

Member Typedef Documentation

◆ value_type

Constructor & Destructor Documentation

◆ atomic_counter() [1/3]

mn::atomic_counter::atomic_counter ( )

Construct a new atomic_counter and initializes it to zero.

◆ atomic_counter() [2/3]

mn::atomic_counter::atomic_counter ( const value_type value)

Construct a new atomic_counter and initializes it with the given value.

Parameters
valueThe start value for this the counter.

◆ atomic_counter() [3/3]

mn::atomic_counter::atomic_counter ( const atomic_counter other)

Construct a new atomic_counter from a other atomic_counter.

Parameters
otherThe other counter from copyed it.

Member Function Documentation

◆ operator value_type()

mn::atomic_counter::operator value_type ( ) const
inline

Converts the atomic_counter to value_type.

◆ operator!()

bool mn::atomic_counter::operator! ( ) const
inline

If the counter zero?

Returns
If true the counter is zero and if false otherwise.

◆ operator++() [1/2]

value_type mn::atomic_counter::operator++ ( )
inline

Increments the counter.

Returns
The result of the increment.

◆ operator++() [2/2]

value_type mn::atomic_counter::operator++ ( int  )
inline

Increments the counter.

Returns
The previous value.

◆ operator--() [1/2]

value_type mn::atomic_counter::operator-- ( )
inline

Decrements the counter.

Returns
The result of the decrement.

◆ operator--() [2/2]

value_type mn::atomic_counter::operator-- ( int  )
inline

Decrements the counter.

Returns
The previous value.

◆ operator=() [1/2]

atomic_counter & mn::atomic_counter::operator= ( const atomic_counter other)

Assigns the value of another atomic_counter.

◆ operator=() [2/2]

atomic_counter & mn::atomic_counter::operator= ( const value_type value)

Assigns a value to the counter.

Parameters
valueThe value for assigns the counter.

◆ value()

value_type mn::atomic_counter::value ( ) const
inline

Get the value of the counter.

Returns
The value of the counter.

Member Data Documentation

◆ m_atomicCount

_atomic<value_type> mn::atomic_counter::m_atomicCount
private

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