Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CancellationToken Class Reference

Read-only cooperative cancellation token. More...

#include <thread_pool.H>

Collaboration diagram for Aleph::CancellationToken:
[legend]

Classes

class  ConditionVariableRegistration
 RAII guard for condition variable cancellation registration. More...
 

Public Member Functions

 CancellationToken ()=default
 Default constructor.
 
bool stop_requested () const noexcept
 Return true if cancellation has been requested.
 
bool is_cancellation_requested () const noexcept
 Synonym for stop_requested().
 
void throw_if_cancellation_requested () const
 Throw operation_canceled if cancellation was requested.
 
bool valid () const noexcept
 Return true if the token is connected to a source.
 
ConditionVariableRegistration notify_on_cancel (std::condition_variable &cv) const
 Request notification of a condition variable on cancellation.
 

Private Member Functions

 CancellationToken (std::shared_ptr< CancellationState > state) noexcept
 

Private Attributes

std::shared_ptr< CancellationStatestate_
 

Friends

class CancellationSource
 

Detailed Description

Read-only cooperative cancellation token.

Tokens are cheap to copy and can be captured by tasks. They never force a task to stop; instead, user code or higher-level helpers can observe the request and exit gracefully.

Definition at line 199 of file thread_pool.H.

Constructor & Destructor Documentation

◆ CancellationToken() [1/2]

Aleph::CancellationToken::CancellationToken ( std::shared_ptr< CancellationState state)
inlineexplicitprivatenoexcept

Definition at line 203 of file thread_pool.H.

◆ CancellationToken() [2/2]

Aleph::CancellationToken::CancellationToken ( )
default

Default constructor.

Member Function Documentation

◆ is_cancellation_requested()

bool Aleph::CancellationToken::is_cancellation_requested ( ) const
inlinenoexcept

Synonym for stop_requested().

Definition at line 274 of file thread_pool.H.

References stop_requested().

◆ notify_on_cancel()

ConditionVariableRegistration Aleph::CancellationToken::notify_on_cancel ( std::condition_variable &  cv) const
inline

Request notification of a condition variable on cancellation.

This is primarily intended for blocking helpers that need to wake up promptly when cooperative cancellation is requested.

Definition at line 294 of file thread_pool.H.

References Aleph::divide_and_conquer_partition_dp(), state_, and stop_requested().

Referenced by Aleph::BoundedChannel< T >::wait_with_cancellation().

◆ stop_requested()

bool Aleph::CancellationToken::stop_requested ( ) const
inlinenoexcept

Return true if cancellation has been requested.

Definition at line 268 of file thread_pool.H.

References Aleph::and, and state_.

Referenced by is_cancellation_requested(), notify_on_cancel(), throw_if_cancellation_requested(), and Aleph::BoundedChannel< T >::wait_with_cancellation().

◆ throw_if_cancellation_requested()

void Aleph::CancellationToken::throw_if_cancellation_requested ( ) const
inline

◆ valid()

bool Aleph::CancellationToken::valid ( ) const
inlinenoexcept

Return true if the token is connected to a source.

Definition at line 287 of file thread_pool.H.

References state_.

Friends And Related Symbol Documentation

◆ CancellationSource

Definition at line 206 of file thread_pool.H.

Member Data Documentation

◆ state_

std::shared_ptr<CancellationState> Aleph::CancellationToken::state_
private

Definition at line 201 of file thread_pool.H.

Referenced by notify_on_cancel(), stop_requested(), and valid().


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