callonce  1.0.0
Header-only memoized call-once wrapper for any C++ callable
fedem::utility::single_threaded Class Reference

Execution policy with no synchronisation overhead. The CTAD default. More...

#include <memoized_invoke.hh>

Public Member Functions

bool try_enter ()
 Attempt to move from the not-started/running state into running. More...
 
void mark_done () noexcept
 Transition to the done state. Called after a successful invocation. More...
 
void mark_free () noexcept
 Transition back to not-started. Called on reset and on exception rollback. More...
 
bool is_done () const noexcept
 
void wait () const noexcept
 No-op: a single-threaded caller is never actually blocked. More...
 

Private Attributes

detail::execution_state state_ { detail::execution_state::not_started }
 

Detailed Description

Execution policy with no synchronisation overhead. The CTAD default.

single_threaded implements the ExecutionPolicy interface expected by memoized_invoke using a plain, non-atomic state variable. Every operation is a single unsynchronised load or store, so there is no cost beyond that of a bare enum.

Warning
Not thread-safe. Use it only when the owning memoized_invoke is confined to one thread, or when some external lock already serialises access. For concurrent one-time initialisation use lock_free.
See also
lock_free

Member Function Documentation

◆ try_enter()

bool fedem::utility::single_threaded::try_enter ( )
inline

Attempt to move from the not-started/running state into running.

Returns
false once the state is done (nothing left to do); true otherwise, after setting the state to running.

References fedem::utility::detail::done, fedem::utility::detail::running, and state_.

◆ mark_done()

void fedem::utility::single_threaded::mark_done ( )
inlinenoexcept

Transition to the done state. Called after a successful invocation.

References fedem::utility::detail::done, and state_.

◆ mark_free()

void fedem::utility::single_threaded::mark_free ( )
inlinenoexcept

Transition back to not-started. Called on reset and on exception rollback.

References fedem::utility::detail::not_started, and state_.

◆ is_done()

bool fedem::utility::single_threaded::is_done ( ) const
inlinenoexcept
Returns
true if the callable has run to completion and the value is cached.

References fedem::utility::detail::done, and state_.

◆ wait()

void fedem::utility::single_threaded::wait ( ) const
inlinenoexcept

No-op: a single-threaded caller is never actually blocked.

Member Data Documentation

◆ state_

detail::execution_state fedem::utility::single_threaded::state_ { detail::execution_state::not_started }
private

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