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

Thread-local cancellation context for implicit token propagation. More...

#include <enhanced_cancellation_token.h>

Collaboration diagram for kcenon::thread::cancellation_context:
Collaboration graph

Classes

class  guard
 RAII guard for push/pop operations. More...
 

Static Public Member Functions

static auto current () -> enhanced_cancellation_token
 Gets the current thread's cancellation token.
 
static auto push (enhanced_cancellation_token token) -> void
 Pushes a token to the thread-local stack.
 
static auto pop () -> void
 Pops a token from the thread-local stack.
 

Private Member Functions

 cancellation_context ()=delete
 

Detailed Description

Thread-local cancellation context for implicit token propagation.

Provides a way to implicitly propagate cancellation tokens through the call stack using thread-local storage.

Usage Example

void outer_function(enhanced_cancellation_token token) {
inner_function(); // Can access token via current()
}
void inner_function() {
if (token.is_cancelled()) {
return;
}
// do work
}
static auto current() -> enhanced_cancellation_token
Gets the current thread's cancellation token.
Advanced cancellation token with timeout, deadline, and reason support.

Definition at line 489 of file enhanced_cancellation_token.h.

Constructor & Destructor Documentation

◆ cancellation_context()

kcenon::thread::cancellation_context::cancellation_context ( )
privatedelete

Member Function Documentation

◆ current()

auto kcenon::thread::cancellation_context::current ( ) -> enhanced_cancellation_token
staticnodiscard

Gets the current thread's cancellation token.

Returns
The current token, or a new uncancelled token if none.

Definition at line 606 of file enhanced_cancellation_token.cpp.

607 {
608 if (context_stack.empty())
609 {
611 }
612 return context_stack.back();
613 }
static auto create() -> enhanced_cancellation_token
Creates a new cancellation token.

References kcenon::thread::enhanced_cancellation_token::create().

Here is the call graph for this function:

◆ pop()

auto kcenon::thread::cancellation_context::pop ( ) -> void
static

Pops a token from the thread-local stack.

Definition at line 620 of file enhanced_cancellation_token.cpp.

621 {
622 if (!context_stack.empty())
623 {
624 context_stack.pop_back();
625 }
626 }

Referenced by kcenon::thread::cancellation_context::guard::~guard().

Here is the caller graph for this function:

◆ push()

auto kcenon::thread::cancellation_context::push ( enhanced_cancellation_token token) -> void
static

Pushes a token to the thread-local stack.

Parameters
tokenThe token to push.

Definition at line 615 of file enhanced_cancellation_token.cpp.

616 {
617 context_stack.push_back(std::move(token));
618 }

Referenced by kcenon::thread::cancellation_context::guard::guard().

Here is the caller graph for this function:

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