Seastar
High performance C++ framework for concurrent servers
Classes | Public Member Functions | List of all members
seastar::abort_source Class Reference

Detailed Description

Facility to communicate a cancellation request to a fiber. Callbacks can be registered with the abort_source, which are called atomically with a call to request_abort().

#include <seastar/core/abort_source.hh>

Classes

class  subscription
 

Public Member Functions

 abort_source (abort_source &&)=default
 
abort_sourceoperator= (abort_source &&)=default
 
template<typename Func >
optimized_optional< subscriptionsubscribe (Func &&f) noexcept(std::is_nothrow_move_constructible_v< Func >)
 
void request_abort () noexcept
 
void request_abort_ex (std::exception_ptr ex) noexcept
 
template<typename Exception >
void request_abort_ex (Exception &&e) noexcept
 
bool abort_requested () const noexcept
 Returns whether an abort has been requested.
 
void check () const
 Throws a abort_requested_exception if cancellation has been requested.
 
virtual std::exception_ptr get_default_exception () const noexcept
 

Member Function Documentation

◆ get_default_exception()

virtual std::exception_ptr seastar::abort_source::get_default_exception ( ) const
inlinevirtualnoexcept

Returns the default exception type (abort_requested_exception) for this abort source. Overridable by derived classes.

◆ request_abort()

void seastar::abort_source::request_abort ( )
inlinenoexcept

Requests that the target operation be aborted. Current subscriptions are invoked inline with this call with a disengaged optional<std::exception_ptr>, and no new ones can be registered. Must be called exactly once, otherwise the program will be aborted.

◆ request_abort_ex() [1/2]

template<typename Exception >
void seastar::abort_source::request_abort_ex ( Exception &&  e)
inlinenoexcept

Requests that the target operation be aborted with a given Exception object. Current subscriptions are invoked inline with this exception, converted to std::exception_ptr, and no new ones can be registered. Must be called exactly once, otherwise the program will be aborted.

◆ request_abort_ex() [2/2]

void seastar::abort_source::request_abort_ex ( std::exception_ptr  ex)
inlinenoexcept

Requests that the target operation be aborted with a given exception_ptr. Current subscriptions are invoked inline with this exception, and no new ones can be registered. Must be called exactly once, otherwise the program will be aborted.

◆ subscribe()

template<typename Func >
optimized_optional<subscription> seastar::abort_source::subscribe ( Func &&  f)
inlinenoexcept

Delays the invocation of the callback f until request_abort() is called.

Returns
an engaged optimized_optional containing a subscription that can be used to control the lifetime of the callback f, if abort_requested() is false. Otherwise, returns a disengaged optimized_optional.

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