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

#include <cancel.hpp>

Public Member Functions

 CancelToken () noexcept=default
 A token that can never be cancelled.
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

Protected Member Functions

 CancelToken (std::shared_ptr< State > state) noexcept

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_

Friends

class CancelSource

Member Typedef Documentation

◆ State

Constructor & Destructor Documentation

◆ CancelToken() [1/2]

pulp::runtime::CancelToken::CancelToken ( )
defaultnoexcept

A token that can never be cancelled.

◆ CancelToken() [2/2]

pulp::runtime::CancelToken::CancelToken ( std::shared_ptr< State > state)
inlineexplicitprotectednoexcept

Member Function Documentation

◆ can_be_cancelled()

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

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

◆ is_cancelled()

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

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 ( )
staticprotected

◆ register_callback()

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

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)
staticprotectednoexcept

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
inlinenodiscardnoexcept

True if both tokens observe the same underlying source.

◆ wait_for_cancellation()

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

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.

◆ CancelSource

friend class CancelSource
friend

Member Data Documentation

◆ state_

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

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