Poco

class AtomicCounter

File Information

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 functionality.

Member Summary

Member Functions: operator !, operator ++, operator --, operator =, operator ValueType, value

Types

ValueType

typedef int ValueType;

The underlying integer type.

Constructors

AtomicCounter

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 ! inline

bool operator ! () const;

Returns true if the counter is zero, false otherwise.

operator ++ inline

ValueType operator ++ ();

Increments the counter and returns the result.

operator ++

ValueType operator ++ (
    int
);

Increments the counter and returns the previous value.

operator -- inline

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;

Converts the AtomicCounter to ValueType.

value inline

ValueType value() const;

Returns the value of the counter.