Library: Foundation
Package: Core
Header: Poco/AtomicCounter.h
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:
Member Functions: operator !, operator ++, operator --, operator =, operator ValueType, value
typedef int ValueType;
The underlying integer type.
Creates a new AtomicCounter and initializes it to zero.
explicit AtomicCounter(
ValueType initialValue
);
Creates a new AtomicCounter and initializes it with the given value.
AtomicCounter(
const AtomicCounter & counter
);
Creates the counter by copying another one.
~AtomicCounter();
Destroys the AtomicCounter.
bool operator ! () const;
Returns true if the counter is zero, false otherwise.
ValueType operator ++ ();
Increments the counter and returns the result.
ValueType operator ++ (
int
);
Increments the counter and returns the previous value.
ValueType operator -- ();
Decrements the counter and returns the result.
ValueType operator -- (
int
);
Decrements the counter and returns the previous value.
AtomicCounter & operator = (
const AtomicCounter & counter
);
Assigns the value of another AtomicCounter.
AtomicCounter & operator = (
ValueType value
);
Assigns a value to the counter.
operator ValueType() const;
Returns the value of the counter.
ValueType value() const;
Returns the value of the counter.