Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::atomic_monotonic_counter Class Reference

A thread-safe atomic counter. More...

Public Types

using value_type = std::uint64_t
 The value type of the counter.
 

Public Member Functions

constexpr atomic_monotonic_counter () noexcept
 Default constructor initializing counter to 0.
 
constexpr atomic_monotonic_counter (value_type const initial_value) noexcept
 Constructor with initial value.
 
auto load () const noexcept -> value_type
 Atomically loads and returns the current counter value.
 
 operator value_type () const noexcept
 Implicit conversion to the counter's value type.
 
auto operator++ () noexcept -> value_type
 Pre-increment operator.
 
auto operator++ (int) noexcept -> value_type
 Post-increment operator.
 

Detailed Description

A thread-safe atomic counter.

A 64-bit unsigned monotonic counter using compiler atomic intrinsics, intended for use when the C++ standard library atomic header is not available.

Note: All operations use sequentially consistent memory ordering.

Member Typedef Documentation

◆ value_type

The value type of the counter.

Constructor & Destructor Documentation

◆ atomic_monotonic_counter() [1/2]

arene::base::atomic_monotonic_counter::atomic_monotonic_counter ( )
inlineconstexprnoexcept

Default constructor initializing counter to 0.

◆ atomic_monotonic_counter() [2/2]

arene::base::atomic_monotonic_counter::atomic_monotonic_counter ( value_type const initial_value)
inlineexplicitconstexprnoexcept

Constructor with initial value.

Parameters
initial_valueThe initial value for the counter

Member Function Documentation

◆ load()

auto arene::base::atomic_monotonic_counter::load ( ) const -> value_type
inlinenoexcept

Atomically loads and returns the current counter value.

Returns
The current counter value

◆ operator value_type()

arene::base::atomic_monotonic_counter::operator value_type ( ) const
inlinenoexcept

Implicit conversion to the counter's value type.

Returns
The current counter value

◆ operator++() [1/2]

auto arene::base::atomic_monotonic_counter::operator++ ( ) -> value_type
inlinenoexcept

Pre-increment operator.

Returns
The value of the counter after modification

Note: This returns a copy of the counter value, not a reference to the counter.

◆ operator++() [2/2]

auto arene::base::atomic_monotonic_counter::operator++ ( int ) -> value_type
inlinenoexcept

Post-increment operator.

Returns
The value before incrementing

Note: This returns a copy of the counter value, not a reference to the counter.


The documentation for this class was generated from the following file: