18#include <condition_variable>
24#include <unordered_map>
30 class enhanced_cancellation_token;
31 class cancellation_callback_guard;
32 class cancellation_scope;
33 class cancellation_context;
198 auto
cancel(const
std::
string& message) ->
void;
206 auto
cancel(
std::exception_ptr ex) ->
void;
260 [[nodiscard]] auto
deadline() const ->
std::chrono::steady_clock::time_point;
306 auto
wait() const ->
void;
313 [[nodiscard]] auto
wait_for(
std::chrono::milliseconds timeout) const ->
bool;
330 const
std::
string& message,
331 std::optional<
std::exception_ptr> ex) ->
void;
444 [[nodiscard]]
auto is_cancelled() const ->
bool;
451 [[nodiscard]] auto check_cancelled() const -> common::VoidResult;
507 static auto pop() -> void;
Exception class for operation cancellation.
Cancellation reason structure for enhanced cancellation tokens.
RAII guard for automatic callback unregistration.
cancellation_callback_guard(const cancellation_callback_guard &)=delete
enhanced_cancellation_token * token_
enhanced_cancellation_token::callback_handle handle_
auto operator=(const cancellation_callback_guard &) -> cancellation_callback_guard &=delete
RAII guard for push/pop operations.
auto operator=(guard &&) -> guard &=delete
guard(const guard &)=delete
auto operator=(const guard &) -> guard &=delete
Thread-local cancellation context for implicit token propagation.
cancellation_context()=delete
Structured cancellation scope with check points.
auto operator=(cancellation_scope &&) -> cancellation_scope &=delete
cancellation_scope(const cancellation_scope &)=delete
cancellation_scope(cancellation_scope &&)=delete
auto operator=(const cancellation_scope &) -> cancellation_scope &=delete
~cancellation_scope()=default
Destructor.
Advanced cancellation token with timeout, deadline, and reason support.
std::function< void()> callback_type
Simple callback function type.
static auto create() -> enhanced_cancellation_token
Creates a new cancellation token.
enhanced_cancellation_token(const enhanced_cancellation_token &)=default
Copy constructor (shares state).
static auto create_linked_with_timeout(const enhanced_cancellation_token &parent, std::chrono::milliseconds timeout) -> enhanced_cancellation_token
Creates a linked token with additional timeout.
std::shared_ptr< state > state_
enhanced_cancellation_token()
Default constructor creates a new token.
auto has_timeout() const -> bool
Checks if the token has a timeout or deadline.
auto do_cancel(cancellation_reason::type reason_type, const std::string &message, std::optional< std::exception_ptr > ex) -> void
auto wait_for(std::chrono::milliseconds timeout) const -> bool
Waits for cancellation with a timeout.
auto remaining_time() const -> std::chrono::milliseconds
Gets the remaining time before timeout/deadline.
std::function< void(const cancellation_reason &)> callback_with_reason_type
Callback function type with reason parameter.
static auto create_linked(std::initializer_list< enhanced_cancellation_token > tokens) -> enhanced_cancellation_token
Creates a token linked to parent tokens.
auto is_cancelled() const -> bool
Checks if the token has been cancelled.
auto wait_until(std::chrono::steady_clock::time_point deadline) const -> bool
Waits for cancellation until a deadline.
auto unregister_callback(callback_handle handle) -> void
Unregisters a previously registered callback.
static auto create_with_timeout(std::chrono::milliseconds timeout) -> enhanced_cancellation_token
Creates a token that auto-cancels after the specified timeout.
static auto create_with_deadline(std::chrono::steady_clock::time_point deadline) -> enhanced_cancellation_token
Creates a token that auto-cancels at the specified deadline.
auto extend_timeout(std::chrono::milliseconds additional) -> void
Extends the timeout by the specified duration.
auto deadline() const -> std::chrono::steady_clock::time_point
Gets the deadline time point.
std::size_t callback_handle
Callback handle type for registration management.
enhanced_cancellation_token(enhanced_cancellation_token &&) noexcept=default
Move constructor.
auto cancel() -> void
Cancels the token.
static auto start_timeout_timer(std::weak_ptr< state > state_weak, std::chrono::steady_clock::time_point deadline) -> void
auto wait() const -> void
Waits until the token is cancelled.
auto is_cancellation_requested() const -> bool
Checks if cancellation has been requested.
auto get_reason() const -> std::optional< cancellation_reason >
Gets the cancellation reason.
auto operator=(const enhanced_cancellation_token &) -> enhanced_cancellation_token &=default
Copy assignment (shares state).
auto register_callback(callback_type callback) -> callback_handle
Registers a callback to be invoked on cancellation.
auto check_cancelled() const -> common::VoidResult
Checks if the token has been cancelled and returns an error result.
@ callback
Call user callback for custom decision.
Error codes and utilities for the thread system.
Core threading foundation of the thread system library.
Holds information about why a cancellation occurred.