Fray Engine
Loading...
Searching...
No Matches
fray::threads::StopToken Class Reference

Cooperative cancellation shared by every copy of a token. Copies share one state guarded by an internal mutex, so any thread may use any copy. More...

#include <thread_manager.hpp>

Classes

struct  State

Public Member Functions

bool stopRequested () const
 True once requestStop() was called on any copy. Briefly takes the token's mutex.
template<typename Rep, typename Period>
bool waitFor (const std::chrono::duration< Rep, Period > &duration) const
 Sleeps for up to duration; returns true as soon as a stop is requested.
void requestStop () const
 Requests a stop on all copies and wakes any waitFor() callers. Safe from any thread; idempotent.

Private Attributes

std::shared_ptr< State > _state = std::make_shared<State>()

Detailed Description

Cooperative cancellation shared by every copy of a token. Copies share one state guarded by an internal mutex, so any thread may use any copy.

Definition at line 29 of file thread_manager.hpp.

Member Function Documentation

◆ requestStop()

void fray::threads::StopToken::requestStop ( ) const
inline

Requests a stop on all copies and wakes any waitFor() callers. Safe from any thread; idempotent.

Definition at line 64 of file thread_manager.hpp.

◆ stopRequested()

bool fray::threads::StopToken::stopRequested ( ) const
inline

True once requestStop() was called on any copy. Briefly takes the token's mutex.

Definition at line 44 of file thread_manager.hpp.

◆ waitFor()

template<typename Rep, typename Period>
bool fray::threads::StopToken::waitFor ( const std::chrono::duration< Rep, Period > & duration) const
inline

Sleeps for up to duration; returns true as soon as a stop is requested.

Parameters
durationMaximum time to sleep. The token's mutex is released while sleeping.
Returns
true if a stop was requested (immediately or during the wait); false if the time ran out.

Definition at line 56 of file thread_manager.hpp.

Member Data Documentation

◆ _state

std::shared_ptr<State> fray::threads::StopToken::_state = std::make_shared<State>()
private

State shared by all copies of this token.

Definition at line 40 of file thread_manager.hpp.


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