Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::runtime::CancellationToken Class Reference

Former name of the shared token. More...

#include <cancel.hpp>

Public Member Functions

 CancellationToken ()
void cancel () noexcept
bool is_cancelled () const noexcept
 True once the owning source has been cancelled.
bool can_be_cancelled () const noexcept
 True if this token can ever become cancelled (it is bound to a source).
bool wait_for_cancellation (std::chrono::nanoseconds timeout) const
 Block until cancelled or timeout elapses.
CancelRegistration register_callback (CancelCallback fn) const
 Run fn when the token is cancelled.
bool shares (const CancelToken &other) const noexcept
 True if both tokens observe the same underlying source.

Protected Types

using State = detail::CancelStateBase

Static Protected Member Functions

static bool request_cancel (const std::shared_ptr< State > &state) noexcept
 Mark the state cancelled, wake waiters, run callbacks.
static std::shared_ptr< State > make_state ()

Protected Attributes

std::shared_ptr< State > state_

Detailed Description

Former name of the shared token.

It both observes and requests cancellation: every copy shares state and any copy may call cancel(). A default-constructed instance owns live state. New code should hold a CancelSource and pass CancelToken to the work being cancelled; a CancellationToken converts to CancelToken implicitly. Unlike CancelSource it does not cancel on destruction.

Member Typedef Documentation

◆ State

Constructor & Destructor Documentation

◆ CancellationToken()

pulp::runtime::CancellationToken::CancellationToken ( )

Member Function Documentation

◆ can_be_cancelled()

bool pulp::runtime::CancelToken::can_be_cancelled ( ) const
inlinenodiscardnoexceptinherited

True if this token can ever become cancelled (it is bound to a source).

◆ cancel()

void pulp::runtime::CancellationToken::cancel ( )
inlinenoexcept

◆ is_cancelled()

bool pulp::runtime::CancelToken::is_cancelled ( ) const
inlinenodiscardnoexceptinherited

True once the owning source has been cancelled.

Lock-free and allocation-free; safe to poll from the audio thread.

◆ make_state()

std::shared_ptr< State > pulp::runtime::CancelToken::make_state ( )
staticprotectedinherited

◆ register_callback()

CancelRegistration pulp::runtime::CancelToken::register_callback ( CancelCallback fn) const
nodiscardinherited

Run fn when the token is cancelled.

If it is already cancelled, fn runs immediately on the calling thread and the returned registration is empty. On a token that cannot be cancelled fn never runs and the registration is empty. Callbacks run in registration order.

◆ request_cancel()

bool pulp::runtime::CancelToken::request_cancel ( const std::shared_ptr< State > & state)
staticprotectednoexceptinherited

Mark the state cancelled, wake waiters, run callbacks.

Returns true if this call performed the transition.

◆ shares()

bool pulp::runtime::CancelToken::shares ( const CancelToken & other) const
inlinenodiscardnoexceptinherited

True if both tokens observe the same underlying source.

◆ wait_for_cancellation()

bool pulp::runtime::CancelToken::wait_for_cancellation ( std::chrono::nanoseconds timeout) const
inherited

Block until cancelled or timeout elapses.

Returns true when cancelled. On a token that cannot be cancelled this simply sleeps for timeout. Not for the audio thread.

Member Data Documentation

◆ state_

std::shared_ptr<State> pulp::runtime::CancelToken::state_
protectedinherited

The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/runtime/include/pulp/runtime/cancel.hpp