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

Cooperative cancellation source paired with CancellationToken. More...

#include <thread_pool.H>

Collaboration diagram for Aleph::CancellationSource:
[legend]

Public Member Functions

 CancellationSource ()=default
 Default constructor.
 
CancellationToken token () const noexcept
 Return a token observing this source.
 
void request_cancel () noexcept
 Request cancellation for all derived tokens.
 
void cancel () noexcept
 Synonym for request_cancel().
 
bool stop_requested () const noexcept
 Return true if cancellation has already been requested.
 
void reset ()
 Reset the source so future tokens observe a fresh state.
 

Private Attributes

std::shared_ptr< cancellation_detail::Exact_State > state_
 

Detailed Description

Cooperative cancellation source paired with CancellationToken.

Copies of a source share its state. Several threads may call request_cancel(), stop_requested() and token() on the same source at the same time, but reset() and assignment change the source, so they must not run at the same time as another use of it.

Definition at line 495 of file thread_pool.H.

Constructor & Destructor Documentation

◆ CancellationSource()

Aleph::CancellationSource::CancellationSource ( )
default

Default constructor.

Member Function Documentation

◆ cancel()

void Aleph::CancellationSource::cancel ( )
inlinenoexcept

Synonym for request_cancel().

Definition at line 525 of file thread_pool.H.

References request_cancel().

◆ request_cancel()

void Aleph::CancellationSource::request_cancel ( )
inlinenoexcept

Request cancellation for all derived tokens.

It notifies the condition variables registered with its tokens. For a registration made with a mutex, it first takes and releases that mutex, so treat this call as taking each of those mutexes, one at a time (see CancellationToken::notify_on_cancel(cv, mutex)).

Definition at line 517 of file thread_pool.H.

References state_.

Referenced by cancel().

◆ reset()

void Aleph::CancellationSource::reset ( )
inline

Reset the source so future tokens observe a fresh state.

Definition at line 534 of file thread_pool.H.

References state_.

◆ stop_requested()

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

Return true if cancellation has already been requested.

Definition at line 528 of file thread_pool.H.

References state_.

◆ token()

CancellationToken Aleph::CancellationSource::token ( ) const
inlinenoexcept

Return a token observing this source.

Definition at line 505 of file thread_pool.H.

References state_.

Referenced by example_structured_concurrency().

Member Data Documentation

◆ state_

std::shared_ptr<cancellation_detail::Exact_State> Aleph::CancellationSource::state_
private
Initial value:
=
std::make_shared<cancellation_detail::Exact_State>()

Definition at line 497 of file thread_pool.H.

Referenced by request_cancel(), reset(), stop_requested(), and token().


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