#include <AtomicCounter.h>
Public Types | |
typedef int | ValueType |
Public Member Functions | |
AtomicCounter (const AtomicCounter &counter) | |
AtomicCounter (ValueType initialValue) | |
Creates a new AtomicCounter and initializes it to zero. | |
AtomicCounter () | |
The underlying integer type. | |
operator ValueType () const | |
Assigns a value to the counter. | |
bool | operator! () const |
Decrements the counter and returns the previous value. | |
ValueType | operator++ (int) |
Increments the counter and returns the result. | |
ValueType | operator++ () |
Returns the value of the counter. | |
ValueType | operator-- (int) |
Decrements the counter and returns the result. | |
ValueType | operator-- () |
Increments the counter and returns the previous value. | |
AtomicCounter & | operator= (ValueType value) |
Assigns the value of another AtomicCounter. | |
AtomicCounter & | operator= (const AtomicCounter &counter) |
Destroys the AtomicCounter. | |
ValueType | value () const |
Returns the value of the counter. | |
~AtomicCounter () | |
Creates the counter by copying another one. | |
Private Types | |
typedef volatile LONG | ImplType |
Returns true if the counter is zero, false otherwise. | |
Private Attributes | |
ImplType | _counter |
This class implements a simple counter, which provides atomic operations that are safe to use in a multithreaded environment.
Typical usage of AtomicCounter is for implementing reference counting and similar things.
On some platforms, the implementation of AtomicCounter is based on atomic primitives specific to the platform (such as InterlockedIncrement, etc. on Windows), and thus very efficient. On platforms that do not support atomic primitives, operations are guarded by a FastMutex.
The following platforms currently have atomic primitives:
Definition at line 56 of file AtomicCounter.h.
typedef volatile LONG Poco::AtomicCounter::ImplType [private] |
Returns true if the counter is zero, false otherwise.
Definition at line 120 of file AtomicCounter.h.
typedef int Poco::AtomicCounter::ValueType |
Definition at line 76 of file AtomicCounter.h.
Poco::AtomicCounter::AtomicCounter | ( | ) |
The underlying integer type.
Definition at line 47 of file AtomicCounter.cpp.
Poco::AtomicCounter::AtomicCounter | ( | AtomicCounter::ValueType | initialValue | ) | [explicit] |
Creates a new AtomicCounter and initializes it to zero.
Definition at line 53 of file AtomicCounter.cpp.
Poco::AtomicCounter::AtomicCounter | ( | const AtomicCounter & | counter | ) |
Creates a new AtomicCounter and initializes it with the given value.
Definition at line 59 of file AtomicCounter.cpp.
Poco::AtomicCounter::~AtomicCounter | ( | ) |
Creates the counter by copying another one.
Definition at line 65 of file AtomicCounter.cpp.
Poco::AtomicCounter::operator AtomicCounter::ValueType | ( | ) | const [inline] |
Assigns a value to the counter.
Definition at line 144 of file AtomicCounter.h.
bool Poco::AtomicCounter::operator! | ( | ) | const [inline] |
Decrements the counter and returns the previous value.
Definition at line 184 of file AtomicCounter.h.
AtomicCounter::ValueType Poco::AtomicCounter::operator++ | ( | int | ) | [inline] |
Increments the counter and returns the result.
Definition at line 162 of file AtomicCounter.h.
AtomicCounter::ValueType Poco::AtomicCounter::operator++ | ( | ) | [inline] |
Returns the value of the counter.
Definition at line 156 of file AtomicCounter.h.
AtomicCounter::ValueType Poco::AtomicCounter::operator-- | ( | int | ) | [inline] |
Decrements the counter and returns the result.
Definition at line 176 of file AtomicCounter.h.
AtomicCounter::ValueType Poco::AtomicCounter::operator-- | ( | ) | [inline] |
Increments the counter and returns the previous value.
Definition at line 170 of file AtomicCounter.h.
AtomicCounter & Poco::AtomicCounter::operator= | ( | AtomicCounter::ValueType | value | ) |
Assigns the value of another AtomicCounter.
Definition at line 77 of file AtomicCounter.cpp.
AtomicCounter & Poco::AtomicCounter::operator= | ( | const AtomicCounter & | counter | ) |
Destroys the AtomicCounter.
Definition at line 70 of file AtomicCounter.cpp.
AtomicCounter::ValueType Poco::AtomicCounter::value | ( | ) | const [inline] |
Returns the value of the counter.
Definition at line 150 of file AtomicCounter.h.
ImplType Poco::AtomicCounter::_counter [private] |
Definition at line 131 of file AtomicCounter.h.