Skip to main content

CoreHandle

Struct CoreHandle 

Source
pub struct CoreHandle { /* private fields */ }
Expand description

Handle to a core’s reactor thread.

Provides lock-free communication with the core via SPSC queues and credit-based flow control for backpressure.

Implementations§

Source§

impl CoreHandle

Source

pub fn spawn(config: CoreConfig) -> Result<Self, TpcError>

Spawns a new core thread with the given configuration.

§Errors

Returns an error if the thread cannot be spawned.

Source

pub fn spawn_with_operators( config: CoreConfig, operators: Vec<Box<dyn Operator>>, ) -> Result<Self, TpcError>

Spawns a new core thread with operators.

§Errors

Returns an error if the thread cannot be spawned.

Source

pub fn core_id(&self) -> usize

Returns the core ID.

Source

pub fn numa_node(&self) -> usize

Returns the NUMA node for this core.

Source

pub fn is_running(&self) -> bool

Returns true if the core thread is running.

Source

pub fn events_processed(&self) -> u64

Returns the number of events processed by this core.

Source

pub fn outputs_dropped(&self) -> u64

Returns the number of outputs dropped due to a full outbox.

Source

pub fn send(&self, message: CoreMessage) -> Result<(), TpcError>

Sends a message to the core with credit-based flow control.

This method respects the backpressure configuration:

  • Block: Spins until credits available, then sends
  • Drop: Returns Ok but drops the message if no credits
  • Error: Returns error if no credits available
§Errors

Returns an error if the inbox queue is full or credits exhausted (with Error strategy).

Source

pub fn try_send(&self, message: CoreMessage) -> Result<(), TpcError>

Tries to send a message without blocking.

Returns Err if no credits available or queue is full. Does not block regardless of overflow strategy.

§Errors

Returns an error if credits exhausted or queue full.

Source

pub fn send_event(&self, event: Event) -> Result<(), TpcError>

Sends an event to the core with credit-based flow control.

§Errors

Returns an error if the inbox queue is full or backpressure applies.

Source

pub fn try_send_event(&self, event: Event) -> Result<(), TpcError>

Tries to send an event without blocking.

§Errors

Returns an error if credits exhausted or queue full.

Source

pub fn poll_outputs(&self, max_count: usize) -> Vec<Output>

Polls the outbox for outputs.

Returns up to max_count outputs.

§Note

This method allocates memory. For zero-allocation polling, use poll_outputs_into or poll_each instead.

Source

pub fn poll_outputs_into( &self, buffer: &mut Vec<Output>, max_count: usize, ) -> usize

Polls the outbox for outputs into a pre-allocated buffer (zero-allocation).

Outputs are appended to buffer. Returns the number of outputs added. The buffer should have sufficient capacity to avoid reallocation.

§Example
let mut buffer = Vec::with_capacity(1024);

// First poll - fills buffer
let count1 = core_handle.poll_outputs_into(&mut buffer, 100);

// Process outputs...
for output in &buffer[..count1] {
    process(output);
}

// Clear and reuse buffer for next poll (no allocation)
buffer.clear();
let count2 = core_handle.poll_outputs_into(&mut buffer, 100);
Source

pub fn poll_each<F>(&self, max_count: usize, f: F) -> usize
where F: FnMut(Output) -> bool,

Polls the outbox with a callback for each output (zero-allocation).

Processing stops when:

  • max_count outputs have been processed
  • The outbox becomes empty
  • The callback returns false

Returns the number of outputs processed.

§Example
// Process outputs without any allocation
let count = core_handle.poll_each(100, |output| {
    match output {
        Output::Event(event) => handle_event(event),
        _ => {}
    }
    true // Continue processing
});
Source

pub fn poll_output(&self) -> Option<Output>

Polls a single output from the outbox.

Source

pub fn inbox_len(&self) -> usize

Returns the number of pending messages in the inbox.

Source

pub fn outbox_len(&self) -> usize

Returns the number of pending outputs in the outbox.

Source

pub fn is_backpressured(&self) -> bool

Returns true if backpressure is currently active.

Source

pub fn available_credits(&self) -> usize

Returns the number of available credits.

Source

pub fn max_credits(&self) -> usize

Returns the maximum credits configured.

Source

pub fn credit_metrics(&self) -> &CreditMetrics

Returns the credit metrics.

Source

pub fn shutdown(&self)

Signals the core to shut down gracefully.

Source

pub fn join(self) -> Result<(), TpcError>

Waits for the core thread to finish.

§Errors

Returns an error if the thread panicked or returned an error.

Source

pub fn shutdown_and_join(self) -> Result<(), TpcError>

Sends a shutdown signal and waits for the thread to finish.

§Errors

Returns an error if the thread cannot be joined cleanly.

Trait Implementations§

Source§

impl Debug for CoreHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for CoreHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more