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