byteor_abi/layouts/
events_chain.rs

1use indexbus_abi::layouts::{IndexQueue, MpscQueue, SlotPoolLayout};
2use indexbus_abi::{caps as ib_caps, flags as ib_flags, IndexbusAtomicU32, LayoutHeader};
3
4use crate::header::{caps, flags};
5
6/// Shared-memory layout that enables slot passing across a chain of queues.
7///
8/// Conceptually:
9/// - one slot pool (payload bytes)
10/// - `Q` independent SPSC queues that carry slot indices
11/// - `Q` independent MPSC queues that carry slot indices
12///
13/// When adjacent stages are connected by queues within the same chain mapping, the executor can
14/// forward slot indices without copying payload bytes.
15#[repr(C, align(64))]
16pub struct EventsChainLayout<const Q: usize> {
17    /// Common region header (magic/version/capabilities/layout size).
18    pub header: LayoutHeader,
19
20    /// 0 = uninitialized, 1 = initializing, 2 = initialized
21    pub initialized: IndexbusAtomicU32,
22    /// Padding (reserved).
23    pub _pad0: u32,
24
25    /// Pad to 64 so the first 64-byte-aligned section starts at offset 64.
26    pub _pad_to_64: [u8; 40],
27
28    /// Shared slot pool for payload bytes.
29    pub slot_pool: SlotPoolLayout,
30
31    /// Per-edge SPSC queues of slot indices.
32    pub queues: [IndexQueue; Q],
33
34    /// Per-edge MPSC queues of slot indices.
35    pub mpsc_queues: [MpscQueue; Q],
36}
37
38impl<const Q: usize> EventsChainLayout<Q> {
39    /// Capabilities required for this region to be considered compatible.
40    pub const REQUIRED_CAPS: u32 = ib_caps::INDEXBUS_CAP_SUPPORTS_EVENTS
41        | caps::BYTEOR_CAP_SUPPORTS_EVENTS_CHAIN
42        | caps::BYTEOR_CAP_SUPPORTS_EVENTS_CHAIN_MPSC;
43
44    /// Region kind discriminator stored in `LayoutHeader.flags`.
45    pub const REGION_KIND: u16 = flags::BYTEOR_REGION_KIND_EVENTS_CHAIN;
46
47    /// Mask for the low 8 bits containing the region kind discriminator.
48    pub const REGION_KIND_MASK: u16 = ib_flags::INDEXBUS_FLAGS_REGION_KIND_MASK;
49}
50
51/// Concrete v1 events chain layout for `Q=4`.
52///
53/// This is a convenient "known size" layout for tools and smoke tests.
54#[repr(C, align(64))]
55pub struct EventsChainLayout4 {
56    /// Common region header (magic/version/capabilities/layout size).
57    pub header: LayoutHeader,
58
59    /// 0 = uninitialized, 1 = initializing, 2 = initialized
60    pub initialized: IndexbusAtomicU32,
61    /// Padding (reserved).
62    pub _pad0: u32,
63
64    /// Pad to 64 so the first 64-byte-aligned section starts at offset 64.
65    pub _pad_to_64: [u8; 40],
66
67    /// Shared slot pool for payload bytes.
68    pub slot_pool: SlotPoolLayout,
69
70    /// Per-edge SPSC queues of slot indices.
71    pub queues: [IndexQueue; 4],
72
73    /// Per-edge MPSC queues of slot indices.
74    pub mpsc_queues: [MpscQueue; 4],
75}
76
77impl EventsChainLayout4 {
78    /// Capabilities required for this region to be considered compatible.
79    pub const REQUIRED_CAPS: u32 = EventsChainLayout::<4>::REQUIRED_CAPS;
80
81    /// Region kind discriminator stored in `LayoutHeader.flags`.
82    pub const REGION_KIND: u16 = EventsChainLayout::<4>::REGION_KIND;
83
84    /// Mask for the low 8 bits containing the region kind discriminator.
85    pub const REGION_KIND_MASK: u16 = EventsChainLayout::<4>::REGION_KIND_MASK;
86}