Skip to navigation

holoscan::channel_internal::WaitSetSubscriber

Beta
View as Markdown

Attach one private Channel subscriber to a shared backend wait set.

Implementations retain their own backend attachment, which keeps the shared wait backend and subscriber transport port alive independently of the wait-set facade. The facade therefore may be destroyed before attached subscriber wrappers; later attachment destruction still detaches safely. This transport-private interface lets Runtime multiplex inline, Tensor, and Tensor-schema subscribers without exposing backend endpoint or wait-set types.

#include <holoscan/channel_internal/endpoint_interfaces.hpp>

Constructors

WaitSetSubscriber

HOLOSCAN_CORE_EXPORT holoscan::channel_internal::WaitSetSubscriber::WaitSetSubscriber()

Construct a subscriber with no wait context; one is built on the first wait.

Defined out of line because the cached wait context is an incomplete type here, and a defaulted constructor would need its deleter instantiated for construction-time unwinding.

Destructor

~WaitSetSubscriber

virtual HOLOSCAN_CORE_EXPORT holoscan::channel_internal::WaitSetSubscriber::~WaitSetSubscriber()

Assignment operators

operator=

The following overloads are deleted to prevent misuse:

WaitSetSubscriber & holoscan::channel_internal::WaitSetSubscriber::operator=(const WaitSetSubscriber &) = delete;
WaitSetSubscriber & holoscan::channel_internal::WaitSetSubscriber::operator=(WaitSetSubscriber &&) = delete;

Methods

attach_wait_set

virtual expected<std::uint64_t, Error> holoscan::channel_internal::WaitSetSubscriber::attach_wait_set(
void *wait_set
)

Attach this subscriber to an opaque backend wait set.

Returns: Stable wait-set-local identity, or ErrorCode::kInvalidArgument for a null or repeated attachment, or another checked backend setup error.

Parameters

wait_set
void *

Non-null backend-private wait-set address retained by the caller.

detach_wait_set

virtual expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::detach_wait_set() noexcept

Detach this subscriber from its current opaque backend wait set.

A readiness pump or waiter must be joined before this cold lifecycle operation.

Returns: Success after the attachment is retired, including when none was created.

close_local_endpoint

virtual expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::close_local_endpoint() noexcept

Retire source-private local endpoint resources before owner destruction.

This operation is local consumer teardown. It publishes no producer operation or EOS.

Returns: Success, or the allocation-free code of the first detach failure.

has_samples

virtual expected<bool, Error> holoscan::channel_internal::WaitSetSubscriber::has_samples() const

Query pending samples without consuming one.

Readiness is a snapshot hint. A following receive may still report ErrorCode::kNotReady when a lossy replacement, a private control operation, or a competing consumer changed the queue in between. Implementations that own more than one transport lane report the union, so one call answers for the whole subscriber.

Returns: Readiness, or a checked backend query error.

event_wake_enabled

virtual bool holoscan::channel_internal::WaitSetSubscriber::event_wake_enabled() const noexcept

Return whether this subscriber’s service admits kernel event wake.

This function does not throw. It is a frozen creation-time fact, not a runtime state.

Returns: True when the service-static ChannelOptions::enable_event_wake contract is enabled for this endpoint.

wait_set_attached

virtual bool holoscan::channel_internal::WaitSetSubscriber::wait_set_attached() const noexcept

Return whether a backend wait owner currently retains this subscriber’s lanes.

Returns: True for a Runtime pump, cached private wait context, or readiness handle.

readiness_handle_attached

virtual bool holoscan::channel_internal::WaitSetSubscriber::readiness_handle_attached() const noexcept

Return whether a readiness handle specifically retains this subscriber’s lanes.

Returns: True for an external readiness handle, false for a Runtime or private wait set.

readiness

virtual expected<ChannelReadinessHandle, Error> holoscan::channel_internal::WaitSetSubscriber::readiness()

Claim this subscriber’s readiness descriptor for an external event loop.

Returns: A move-only readiness handle, or a checked capability or ownership error.

claim_wait_owner

HOLOSCAN_CORE_EXPORT expected<WaitOwnerGuard, Error> holoscan::channel_internal::WaitSetSubscriber::claim_wait_owner() noexcept

Claim the subscriber’s single wait-owner slot for one complete wait operation.

Returns: An RAII claim, or ErrorCode::kInvalidArgument when another owner is active.

claim_readiness_owner

HOLOSCAN_CORE_EXPORT expected<WaitOwnerGuard, Error> holoscan::channel_internal::WaitSetSubscriber::claim_readiness_owner() noexcept

Claim the owner slot and release a cached private wait context before handle creation.

Returns: An RAII claim, or a checked ownership or detach error.

wait_for_readiness

HOLOSCAN_CORE_EXPORT expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::wait_for_readiness(
std::chrono::steady_clock::time_point deadline,
const std::stop_token *stop_token
) noexcept

Block until this subscriber may have a sample, the deadline expires, or a stop is requested.

The first call builds and caches a private wait set, attaches this subscriber’s transport lanes and a cancellation trigger, and establishes the inbound connection. Later calls reuse that context and rebuild none of it. They are not unconditionally allocation-free: the wait backend records which lanes woke it in a vector that is cleared rather than shrunk and is still empty after setup, so the first later call that a lane actually satisfies grows it once. That growth is bounded by the lane count and does not recur, and the first wait after a cancellation allocates a replacement trigger. Nothing on this path allocates per call.

The wait is event-driven with a bounded recovery poll, not purely event-driven. A publication wakes it from a kernel wait, but transport notification is best effort, so a blocked wait also re-checks readiness about once a second. An idle waiting subscriber therefore costs roughly one wakeup per second rather than nothing at all, and readiness that is reported by a lane which is not attached to the wait set – currently the catalog clock-health lane – is discovered on that fallback rather than by a wake. Treat the interval as an implementation bound rather than a contract.

Cancellation is spelled std::stop_token here on purpose: a token is reusable and standard, where the transport’s own wake primitive is a monotonic single-use latch. This layer owns one of those internally and fires it from a std::stop_callback, so a caller never has to see it or replace it after a cancellation. Naming the transport type here would breach this header’s transport opacity, so the pointer runs the other way: the transport header documents the correspondence.

This function does not throw: an allocation failure on the setup path is translated to ErrorCode::kResourceExhausted rather than crossing the noexcept boundary. One subscriber supports one waiting thread; calls are not internally serialized. A second concurrent waiter is rejected with ErrorCode::kInvalidArgument in every build configuration, rather than being allowed to share the first waiter’s wait context. The rejected call does not disturb the wait already in flight.

Public subscriber helpers retain one owner claim across their complete receive loop and call wait_for_readiness_claimed. This unclaimed entry point remains exported for existing direct callers and acquires its own claim.

Returns: Empty success when a sample may be available, or a checked wait error.

Parameters

deadline
std::chrono::steady_clock::time_point

Steady-clock coordinate after which the wait reports a timeout.

stop_token
const std::stop_token *

Optional borrowed cancellation observer; null disables cancellation.

wait_for_readiness_claimed

HOLOSCAN_CORE_EXPORT expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::wait_for_readiness_claimed(
std::chrono::steady_clock::time_point deadline,
const std::stop_token *stop_token
) noexcept

Wait while the caller retains a successful claim_wait_owner result.

Returns: Empty success when readiness may exist, or a checked wait error.

Parameters

deadline
std::chrono::steady_clock::time_point

Steady-clock coordinate after which the wait reports a timeout.

stop_token
const std::stop_token *

Optional borrowed cancellation observer.

wait_context_runtime

virtual void * holoscan::channel_internal::WaitSetSubscriber::wait_context_runtime() noexcept

Return the private transport runtime used to build this subscriber’s wait context.

The parent Channel runtime outlives every endpoint created from it, so the returned borrow stays valid for this subscriber’s lifetime. This stays in channel_internal rather than being protected so a composite binding can delegate to the inner binding that owns the transport lanes.

Returns: Borrowed backend-private runtime address, or nullptr when this binding has none.

wait_for_readiness_checked

expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::wait_for_readiness_checked(
std::chrono::steady_clock::time_point deadline,
const std::stop_token *stop_token
)

Body of wait_for_readiness.

Separated so the public entry point is a thin translator that can catch an allocation failure and honour its noexcept, rather than asserting a promise the body cannot keep. Private and non-virtual, so it adds no layout or vtable surface.


Member variables

NameTypeDescription
wait_context_std::unique_ptr< SubscriberWaitContext >
waiting_std::atomic_flagClaimed for the duration of one wait, so a second concurrent waiter can be rejected rather than allowed to share wait_context_.

Inner classes

WaitOwnerGuard

class holoscan::channel_internal::WaitSetSubscriber::WaitOwnerGuard

Hold one exclusive wait-owner claim for a complete public wait operation.

NameTypeDescription
waiting_std::atomic_flag *