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

RAII guard for automatic callback unregistration. More...

#include <enhanced_cancellation_token.h>

Collaboration diagram for kcenon::thread::cancellation_callback_guard:
Collaboration graph

Public Member Functions

 cancellation_callback_guard (enhanced_cancellation_token &token, std::function< void()> callback)
 Constructs a guard and registers the callback.
 
 ~cancellation_callback_guard ()
 Destructor unregisters the callback.
 
 cancellation_callback_guard (const cancellation_callback_guard &)=delete
 
auto operator= (const cancellation_callback_guard &) -> cancellation_callback_guard &=delete
 
 cancellation_callback_guard (cancellation_callback_guard &&other) noexcept
 Move constructor.
 
auto operator= (cancellation_callback_guard &&other) noexcept -> cancellation_callback_guard &
 Move assignment.
 

Private Attributes

enhanced_cancellation_tokentoken_
 
enhanced_cancellation_token::callback_handle handle_
 

Detailed Description

RAII guard for automatic callback unregistration.

Automatically unregisters a callback when the guard goes out of scope. Useful for ensuring callbacks are properly cleaned up.

Usage Example

{
cancellation_callback_guard guard(token, [] {
cleanup_resources();
});
do_interruptible_work();
} // Callback auto-unregistered here
RAII guard for automatic callback unregistration.

Definition at line 358 of file enhanced_cancellation_token.h.

Constructor & Destructor Documentation

◆ cancellation_callback_guard() [1/3]

kcenon::thread::cancellation_callback_guard::cancellation_callback_guard ( enhanced_cancellation_token & token,
std::function< void()> callback )

Constructs a guard and registers the callback.

Parameters
tokenThe token to register with.
callbackThe callback to register.

Definition at line 533 of file enhanced_cancellation_token.cpp.

536 : token_(&token), handle_(token.register_callback(std::move(callback)))
537 {
538 }
enhanced_cancellation_token::callback_handle handle_
@ callback
Call user callback for custom decision.

◆ ~cancellation_callback_guard()

kcenon::thread::cancellation_callback_guard::~cancellation_callback_guard ( )

Destructor unregisters the callback.

Definition at line 540 of file enhanced_cancellation_token.cpp.

541 {
542 if (token_ && handle_ != 0)
543 {
545 }
546 }
auto unregister_callback(callback_handle handle) -> void
Unregisters a previously registered callback.

References handle_, token_, and kcenon::thread::enhanced_cancellation_token::unregister_callback().

Here is the call graph for this function:

◆ cancellation_callback_guard() [2/3]

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

◆ cancellation_callback_guard() [3/3]

kcenon::thread::cancellation_callback_guard::cancellation_callback_guard ( cancellation_callback_guard && other)
noexcept

Move constructor.

Definition at line 548 of file enhanced_cancellation_token.cpp.

550 : token_(other.token_), handle_(other.handle_)
551 {
552 other.token_ = nullptr;
553 other.handle_ = 0;
554 }

Member Function Documentation

◆ operator=() [1/2]

auto kcenon::thread::cancellation_callback_guard::operator= ( cancellation_callback_guard && other) -> cancellation_callback_guard&
noexcept

Move assignment.

Definition at line 556 of file enhanced_cancellation_token.cpp.

558 {
559 if (this != &other)
560 {
561 if (token_ && handle_ != 0)
562 {
564 }
565 token_ = other.token_;
566 handle_ = other.handle_;
567 other.token_ = nullptr;
568 other.handle_ = 0;
569 }
570 return *this;
571 }

◆ operator=() [2/2]

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

Member Data Documentation

◆ handle_

enhanced_cancellation_token::callback_handle kcenon::thread::cancellation_callback_guard::handle_
private

Definition at line 392 of file enhanced_cancellation_token.h.

Referenced by ~cancellation_callback_guard().

◆ token_

enhanced_cancellation_token* kcenon::thread::cancellation_callback_guard::token_
private

Definition at line 391 of file enhanced_cancellation_token.h.

Referenced by ~cancellation_callback_guard().


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