byteor_pipeline_kernel/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![deny(missing_docs)]
3#![deny(unreachable_pub, rust_2018_idioms)]
4#![forbid(unsafe_code)]
5
6//! Hot-loop kernel traits and primitives.
7//!
8//! The kernel is IO-free, thread-free, and logging-free; it defines the contracts used by
9//! backings and executors.
10
11pub use indexbus_core::WaitStrategy;
12
13/// Lane traits.
14pub mod lane;
15/// Step primitives.
16pub mod step;
17
18pub use lane::{
19    LaneRx, LaneRxBorrow, LaneRxError, LaneRxSlot, LaneRxSlotBatch, LaneSlot, LaneTx, LaneTxError,
20    LaneTxSlot, LaneTxSlotError, LaneTxWith, LaneTxWithError, LaneTxWithResult,
21};
22pub use step::{
23    publish_slot_with_policy_or_copy, publish_with_policy, recv_map_ok_publish_with_step,
24    recv_select_publish_batch, recv_select_publish_step,
25    recv_slot_filter_forward_publish_slot_step, recv_slot_forward_publish_slot_step,
26    recv_slot_inspect_forward_publish_slot_step, recv_slot_transform_forward_publish_slot_step,
27    recv_transform_publish_batch, recv_transform_publish_step, recv_with_forward_publish_with_step,
28    recv_with_map_ok_publish_with_step, recv_with_map_publish_with_result_step,
29    recv_with_transform_publish_batch, recv_with_transform_publish_step, TransformOutcome,
30};
31
32/// Monotonic sequence number used by SingleRing execution.
33pub type Seq = u64;
34
35/// Helper: compute the ring index for a given sequence and power-of-two `capacity`.
36///
37/// For v1 we primarily use `INDEXBUS_QUEUE_CAPACITY`, but executors may choose a smaller
38/// effective window.
39#[inline]
40pub fn ring_index(seq: Seq, capacity: u64) -> usize {
41    // Modulo is correct even when capacity is not a power of two.
42    (seq % capacity) as usize
43}
44
45/// Passive barrier that reports the latest available sequence.
46///
47/// Backings provide concrete barriers (e.g. cursor barrier, gating barrier). Executors use
48/// barriers to impose Disruptor-style ordering between stages.
49pub trait SeqBarrier {
50    /// Return the currently-available sequence.
51    fn available(&self) -> Seq;
52
53    /// Wait until `available() >= seq` using the provided `WaitStrategy`.
54    #[inline]
55    fn wait_for<W: WaitStrategy>(&self, seq: Seq, wait: &mut W) -> Seq {
56        loop {
57            let avail = self.available();
58            if avail >= seq {
59                return avail;
60            }
61            wait.wait();
62        }
63    }
64}