Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::cancellation_scope Class Reference

Structured cancellation scope with check points. More...

#include <enhanced_cancellation_token.h>

Collaboration diagram for kcenon::thread::cancellation_scope:
Collaboration graph

Public Member Functions

 cancellation_scope (enhanced_cancellation_token token)
 Constructs a scope with the given token.
 
 ~cancellation_scope ()=default
 Destructor.
 
 cancellation_scope (const cancellation_scope &)=delete
 
auto operator= (const cancellation_scope &) -> cancellation_scope &=delete
 
 cancellation_scope (cancellation_scope &&)=delete
 
auto operator= (cancellation_scope &&) -> cancellation_scope &=delete
 
auto is_cancelled () const -> bool
 Checks if the token is cancelled.
 
auto check_cancelled () const -> common::VoidResult
 Checks if the token is cancelled and returns an error result.
 
auto token () const -> const enhanced_cancellation_token &
 Gets the underlying token.
 

Private Attributes

enhanced_cancellation_token token_
 

Detailed Description

Structured cancellation scope with check points.

Provides a convenient way to check for cancellation at various points in code execution.

Usage Example

void process_request(enhanced_cancellation_token token) {
if (scope.check_cancelled().is_err()) return;
step_1();
if (scope.check_cancelled().is_err()) return;
step_2();
if (scope.check_cancelled().is_err()) return;
step_3();
}
Structured cancellation scope with check points.
auto token() const -> const enhanced_cancellation_token &
Gets the underlying token.
Advanced cancellation token with timeout, deadline, and reason support.

Definition at line 420 of file enhanced_cancellation_token.h.

Constructor & Destructor Documentation

◆ cancellation_scope() [1/3]

kcenon::thread::cancellation_scope::cancellation_scope ( enhanced_cancellation_token token)
explicit

Constructs a scope with the given token.

Parameters
tokenThe cancellation token to monitor.

Definition at line 577 of file enhanced_cancellation_token.cpp.

578 : token_(std::move(token))
579 {
580 }

◆ ~cancellation_scope()

kcenon::thread::cancellation_scope::~cancellation_scope ( )
default

Destructor.

◆ cancellation_scope() [2/3]

kcenon::thread::cancellation_scope::cancellation_scope ( const cancellation_scope & )
delete

◆ cancellation_scope() [3/3]

kcenon::thread::cancellation_scope::cancellation_scope ( cancellation_scope && )
delete

Member Function Documentation

◆ check_cancelled()

auto kcenon::thread::cancellation_scope::check_cancelled ( ) const -> common::VoidResult
nodiscard

Checks if the token is cancelled and returns an error result.

Returns
common::VoidResult — error with operation_canceled if cancelled, success otherwise

Definition at line 587 of file enhanced_cancellation_token.cpp.

588 {
589 return token_.check_cancelled();
590 }
auto check_cancelled() const -> common::VoidResult
Checks if the token has been cancelled and returns an error result.

References kcenon::thread::enhanced_cancellation_token::check_cancelled(), and token_.

Here is the call graph for this function:

◆ is_cancelled()

auto kcenon::thread::cancellation_scope::is_cancelled ( ) const -> bool
nodiscard

Checks if the token is cancelled.

Returns
true if cancelled, false otherwise.

Definition at line 582 of file enhanced_cancellation_token.cpp.

583 {
584 return token_.is_cancelled();
585 }
auto is_cancelled() const -> bool
Checks if the token has been cancelled.

References kcenon::thread::enhanced_cancellation_token::is_cancelled(), and token_.

Here is the call graph for this function:

◆ operator=() [1/2]

auto kcenon::thread::cancellation_scope::operator= ( cancellation_scope && ) -> cancellation_scope &=delete
delete

◆ operator=() [2/2]

auto kcenon::thread::cancellation_scope::operator= ( const cancellation_scope & ) -> cancellation_scope &=delete
delete

◆ token()

auto kcenon::thread::cancellation_scope::token ( ) const -> const enhanced_cancellation_token&
nodiscard

Gets the underlying token.

Returns
A const reference to the token.

Definition at line 592 of file enhanced_cancellation_token.cpp.

593 {
594 return token_;
595 }

References token_.

Member Data Documentation

◆ token_

enhanced_cancellation_token kcenon::thread::cancellation_scope::token_
private

Definition at line 460 of file enhanced_cancellation_token.h.

Referenced by check_cancelled(), is_cancelled(), and token().


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