Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches

A thread safe counter. More...

#include <counter.hpp>

Inheritance diagram for counter_t:

Public Member Functions

 counter_t ()
void increment ()
bool decrement ()
bool is_one () const

Detailed Description

A counter_t is a noncopyable thread safe counter, useful for managing the reference count of a shared resource.

Rationale:

counter_t wraps reference count operations that require thread safety into a single class. While this does not guarantee client code will be thread safe, it helps to take a step in that direction. It also cleans up client code and keeps thread-handling scoped to a single file. Consider copy_on_write as an example class that leverages counter_t.

Note
The counter_t class is thread safe when compiled with BOOST_HAS_THREADS defined.

Definition at line 78 of file counter.hpp.

Constructor & Destructor Documentation

◆ counter_t()

counter_t ( )

Default constructor. The counter is initialized to 1.

Definition at line 84 of file counter.hpp.

Member Function Documentation

◆ increment()

void increment ( )

Increments the counter by one.

Definition at line 86 of file counter.hpp.

◆ decrement()

bool decrement ( )

Decrements the counter by one.

Returns
true if the counter is zero at the end of this operation; false otherwise.

Definition at line 88 of file counter.hpp.

◆ is_one()

bool is_one ( ) const

Checks to see if the counter is one.

Returns
true if the counter is one; false otherwise.

Definition at line 90 of file counter.hpp.