|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Provides a mechanism for cooperative cancellation of operations. More...
#include <cancellation_token.h>

Classes | |
| struct | token_state |
Public Member Functions | |
| cancellation_token () | |
| cancellation_token (const cancellation_token &)=default | |
| cancellation_token & | operator= (const cancellation_token &)=default |
| cancellation_token (cancellation_token &&)=default | |
| cancellation_token & | operator= (cancellation_token &&)=default |
| void | cancel () |
| Cancels the operation. | |
| bool | is_cancelled () const |
| Checks if the token has been canceled. | |
| common::VoidResult | check_cancelled () const |
| Checks if the token has been canceled and returns an error result. | |
| void | register_callback (std::function< void()> callback) |
| Registers a callback to be invoked when the token is canceled. | |
| cancellation_token () | |
| cancellation_token (const cancellation_token &)=default | |
| cancellation_token & | operator= (const cancellation_token &)=default |
| cancellation_token (cancellation_token &&)=default | |
| cancellation_token & | operator= (cancellation_token &&)=default |
| void | cancel () |
| Cancels the operation. | |
| bool | is_cancelled () const |
| Checks if the token has been canceled. | |
| common::VoidResult | check_cancelled () const |
| Checks if the token has been canceled and returns an error result. | |
| void | register_callback (std::function< void()> callback) |
| Registers a callback to be invoked when the token is canceled. | |
Static Public Member Functions | |
| static cancellation_token | create () |
| Creates a new cancellation token. | |
| static cancellation_token | create_linked (std::initializer_list< cancellation_token > tokens) |
| Creates a linked token that is canceled when any of the parent tokens are canceled. | |
| static cancellation_token | create () |
| Creates a new cancellation token. | |
| static cancellation_token | create_linked (std::initializer_list< cancellation_token > tokens) |
| Creates a linked token that is canceled when any of the parent tokens are canceled. | |
Private Member Functions | |
| cancellation_token (std::shared_ptr< token_state > state) | |
| cancellation_token (std::shared_ptr< token_state > state) | |
Private Attributes | |
| std::shared_ptr< token_state > | state_ |
Provides a mechanism for cooperative cancellation of operations.
Cancellation tokens allow long-running operations to be gracefully canceled. They are particularly useful for worker threads that need to be notified when their work should be aborted.
Definition at line 30 of file cancellation_token.h.
|
inlineexplicitprivate |
Definition at line 42 of file cancellation_token.h.
|
inline |
Definition at line 47 of file cancellation_token.h.
Referenced by create().

|
default |
|
default |
|
inlineexplicitprivate |
Definition at line 42 of file cancellation_token.h.
|
inline |
Definition at line 47 of file cancellation_token.h.
|
default |
|
default |
|
inline |
Cancels the operation.
Sets the token to the canceled state and invokes all registered callbacks.
Definition at line 107 of file cancellation_token.h.
References kcenon::thread::callback, and state_.
Referenced by kcenon::thread::cancellable_future< R >::cancel(), kcenon::thread::cancellable_future< void >::cancel(), and kcenon::thread::thread_pool::stop_unsafe().

|
inline |
Cancels the operation.
Sets the token to the canceled state and invokes all registered callbacks.
Memory Ordering:
Definition at line 111 of file cancellation_token.h.
References kcenon::thread::callback, and state_.
|
inlinenodiscard |
Checks if the token has been canceled and returns an error result.
Definition at line 139 of file cancellation_token.h.
References is_cancelled(), kcenon::thread::make_error_result(), and kcenon::thread::operation_canceled.

|
inlinenodiscard |
Checks if the token has been canceled and returns an error result.
Definition at line 148 of file cancellation_token.h.
References is_cancelled(), kcenon::thread::make_error_result(), and kcenon::thread::operation_canceled.

|
inlinestatic |
Creates a new cancellation token.
Definition at line 59 of file cancellation_token.h.
References cancellation_token().
Referenced by create_linked(), and kcenon::thread::thread_pool::start().


|
inlinestatic |
Creates a new cancellation token.
Definition at line 59 of file cancellation_token.h.
References cancellation_token().

|
inlinestatic |
Creates a linked token that is canceled when any of the parent tokens are canceled.
| tokens | The parent tokens |
Definition at line 70 of file cancellation_token.h.
References kcenon::thread::callback, and create().

|
inlinestatic |
Creates a linked token that is canceled when any of the parent tokens are canceled.
| tokens | The parent tokens |
Definition at line 70 of file cancellation_token.h.
References kcenon::thread::callback, and create().

|
inlinenodiscard |
Checks if the token has been canceled.
Definition at line 130 of file cancellation_token.h.
References state_.
Referenced by check_cancelled(), cancellable_long_job::do_work(), kcenon::thread::future_job< R >::do_work(), kcenon::thread::job_builder::built_job::do_work(), kcenon::thread::cancellable_future< R >::get(), kcenon::thread::cancellable_future< void >::get(), kcenon::thread::cancellable_future< R >::get_for(), kcenon::thread::cancellable_future< void >::get_for(), kcenon::thread::cancellable_future< R >::is_cancelled(), and kcenon::thread::cancellable_future< void >::is_cancelled().

|
inlinenodiscard |
Checks if the token has been canceled.
Memory Ordering:
Definition at line 139 of file cancellation_token.h.
References state_.
|
default |
|
default |
|
default |
|
default |
|
inline |
Registers a callback to be invoked when the token is canceled.
| callback | The function to call when the token is canceled |
If the token is already canceled, the callback is invoked immediately.
Definition at line 154 of file cancellation_token.h.
References kcenon::thread::callback, and state_.
|
inline |
Registers a callback to be invoked when the token is canceled.
| callback | The function to call when the token is canceled |
If the token is already canceled, the callback is invoked immediately.
Memory Ordering:
Definition at line 167 of file cancellation_token.h.
References kcenon::thread::callback, and state_.
|
private |
Definition at line 39 of file cancellation_token.h.
Referenced by cancel(), is_cancelled(), and register_callback().