Skip to main content

nros_node/executor/
mod.rs

1//! Embedded executor with build-time configured arena.
2//!
3//! Provides `Executor` and `Node` that work with the compile-time
4//! selected RMW backend (zenoh, XRCE-DDS, or C FFI).
5//!
6//! # Example
7//!
8//! ```ignore
9//! use nros_node::executor::*;
10//! use std_msgs::msg::Int32;
11//!
12//! let config = ExecutorConfig::from_env().node_name("my_node");
13//! let mut executor = Executor::open(&config)?;
14//! let mut node = executor.create_node("my_node")?;
15//!
16//! let publisher = node.create_publisher::<Int32>("/chatter")?;
17//! publisher.publish(&Int32 { data: 42 })?;
18//!
19//! loop {
20//!     executor.spin_once(core::time::Duration::from_millis(10));
21//! }
22//! ```
23
24#[cfg(any(has_rmw, test))]
25pub mod action_core;
26#[cfg(any(has_rmw, test))]
27mod arena;
28// phase-412 #4 — the compile-time half of "is the arena big enough?". Not
29// `has_rmw`-gated: it reads only `config`, and the check it carries must run in
30// every compilation of this crate, whatever the backend.
31pub mod arena_oracle;
32// phase-392 W6 — the named `.bss` static the `alloc` convenience constructors
33// serve their backing from. `alloc`-gated because it exists to replace a
34// `Box::leak`: a no-alloc entry already supplies its own `static` through
35// `open_in`, and reserving a second one there would be pure waste in exactly
36// the images this campaign is about.
37#[cfg(all(any(has_rmw, test), feature = "alloc"))]
38mod backing;
39// issue 1571 — the spawned sched tasks' half of the same machinery: the ENTRY owns
40// the static (it knows the tier count), boards hand each tier a slot.
41#[cfg(all(any(has_rmw, test), feature = "alloc"))]
42pub use backing::{
43    EXECUTOR_BACKING_DEFAULT_U64S, SCHED_TASK_TCB_U64S, SchedTaskBackingShort,
44    SchedTaskExecutorBacking, SchedTaskExecutorBackingSlot, SchedTaskMemory, SchedTaskMemoryRaw,
45    SchedTaskMemorySet, SchedTaskSetupGate, SchedTaskSetupGuard, check_sched_task_executor_backing,
46};
47// Phase 8 (autoware-safety-island `docs/design/callback_tracing.rst`) —
48// callback-level dispatch tracing. Same gating shape as `wake_probe`, for the
49// same reason: hot-path hooks that must vanish in production. The module ALSO
50// self-gates (`#![cfg(feature = "trace-callbacks")]`), so the call sites use
51// paired stubs rather than naming it directly.
52#[cfg(all(any(has_rmw, test), feature = "trace-callbacks"))]
53pub mod callback_trace;
54// issue 2641 -- the application's trace markers. UNGATED: the id range check
55// runs in every build, and only the emission needs `callback_trace`.
56pub mod trace_marker;
57// phase-463 W7 — the host profile (`profile-mode`, host-only: it needs `std`
58// and no RTOS umbrella resolves it).
59#[cfg(all(any(has_rmw, test), feature = "profile-mode"))]
60pub mod profile;
61// phase-457 W5 (issue 1522) — the shape a DECLARED subscription lowers to.
62// UNGATED on purpose: the executor half needs an RMW seam, but the recorder
63// half runs in a probe that opens no executor, and both must read the same
64// enum.
65pub mod declared_shape;
66#[cfg(any(has_rmw, test))]
67mod handles;
68// issue 0669 / phase-359 W10 — `pub mod handoff` stood here. `Handoff<M, N>`
69// was optional sugar over `Arc<Mutex<heapless::Vec<M, N>>>` for the
70// cross-priority bridge pattern (phase-104.E.3), it was `std`-gated on
71// `std::sync::Mutex` alone, and it had no consumer anywhere in the tree — not
72// one call site in `packages/` or `examples/` since it landed. Deleted rather
73// than ported: the only portable mutex reachable from here costs a `spin`
74// dependency edge on every build of this crate (measured: `spin` is in NO
75// board's graph today), and an API with no consumer has no evidence its shape
76// is the right one. The pattern it wrapped is six lines and is written out in
77// issue 0669.
78#[cfg(any(has_rmw, test))]
79pub mod monitor;
80#[cfg(any(has_rmw, test))]
81mod node;
82#[cfg(any(has_rmw, test))]
83pub use node::fit_runtime_qos;
84#[cfg(any(has_rmw, test))]
85pub mod node_record;
86#[cfg(any(has_rmw, test))]
87mod node_wake;
88// phase-436 -- one backend wake slot shared by every executor over a session.
89#[cfg(any(all(feature = "alloc", feature = "rmw-cffi"), test))]
90pub(crate) mod wake_fanout;
91// phase-397 W2 -- the per-entity wake: an arrival names its slot and owner.
92#[cfg(all(feature = "alloc", feature = "rmw-cffi"))]
93pub(crate) mod entity_wake;
94#[cfg(any(has_rmw, test))]
95/// Installing a port's park primitive, with the wake-object
96/// constraint stated once instead of per board.
97pub mod port_park;
98// phase-359 W10 — the allocate/spawn/join helper moved to
99// `nros_platform_api::task`, beside the ABI it wraps, once `nros-cpp` became a
100// third caller. Reached through a `use` below rather than a module here.
101#[cfg(any(has_rmw, test))]
102pub(crate) mod ready_set;
103// phase-457 W3 — the per-endpoint half of `registration_path`, reported by the
104// one site that knows it. Behind a feature only a metadata probe turns on.
105#[cfg(feature = "registration-observer")]
106pub mod registration_observer;
107pub mod sched_context;
108// Issue 1971 -- the image's launch remap table, one `const` table in flash
109// that every executor reads (RFC-0107 step 1). No RMW: it is plain data.
110pub mod launch_remap;
111pub mod session_props;
112
113/// The executor's lock.
114pub mod exec_lock;
115// phase-509 P7 (RFC-0108 D8) -- each executor's level and the image's per-level
116// liveness. Plain atomics, no RMW: every build carries it.
117pub mod level_liveness;
118pub use level_liveness::{
119    MAX_LEVELS, every_level_alive, level_count, level_last_spin_us, level_spins, sched_task_level,
120    sched_task_level_by, set_level_count, take_every_level_alive,
121};
122// phase-509 P6 (RFC-0108 D3/D7) -- the per-core scheduler and the per-level
123// worker the executor's dispatcher splits into.
124#[cfg(any(has_rmw, test))]
125pub(crate) mod scheduler;
126#[cfg(any(has_rmw, test))]
127pub(crate) mod spin;
128// Issue 2146 -- deferred dispatch for a hand-written host (RFC-0112 D2).
129#[cfg(any(has_rmw, test))]
130mod deferred;
131#[cfg(any(has_rmw, test))]
132pub(crate) mod spsc_ring;
133#[cfg(any(has_rmw, test))]
134mod storage;
135#[cfg(any(has_rmw, test))]
136pub(crate) mod triple_buffer;
137// Issue 2541 -- callback slot masks wider than one `u64`.
138pub(crate) mod slot_mask;
139mod types;
140#[cfg(all(any(has_rmw, test), feature = "wake-latency-probe"))]
141pub mod wake_probe;
142
143#[cfg(any(has_rmw, test))]
144pub mod action;
145
146/// The sealed trait the C/C++ shims import for the
147/// executor's FFI entry points. `nros` does not re-export it.
148#[cfg(any(has_rmw, test))]
149pub mod ffi;
150
151// MockSession-based tests. Disabled when any rmw-* feature is active because
152// feature unification under `cargo test --workspace` flips `ConcreteSession`
153// to a real backend handle (e.g. UorbSession when rmw-uorb is on transitively
154// via the workspace), breaking the type signatures the tests expect.
155// `feature = "alloc"` is part of the gate, not decoration. The crate is
156// `#![no_std]`; `tests.rs` uses `std::` in 155 places (in scope because
157// `lib.rs` brings `std` in under `cfg(test)`) and calls `from_session`, which
158// is itself `#[cfg(feature = "alloc")]`. Without the
159// feature in the gate, a plain `cargo test -p nros-node` compiles this module
160// into a no_std crate and produces 252 errors, 192 of them "cannot find module
161// or crate `std`" — an incomprehensible wall for anyone running the obvious
162// command, and unrelated to whatever they were changing.
163//
164// These tests genuinely need a host: they spawn threads, sleep, and read the
165// wall clock. Gating them is not hiding coverage, it is declaring what they
166// already required. `cargo test -p nros-node --features alloc` runs them; the
167// test harness has `std` whatever the features say (phase-359 W10).
168// phase-515 R10 -- the deprecated `Executor` parameter forms keep their tests
169// for the release they remain.
170#[allow(deprecated)]
171#[cfg(all(test, feature = "alloc", not(feature = "rmw-cffi")))]
172mod tests;
173
174// phase-444 — the two `wait_for_*` decisions, in their own file rather
175// than appended to `tests.rs`. Same gate, same fixture (`MockSession`);
176// separate because what they pin is a CONTRACT choice, not executor
177// mechanics, and a reader looking for "why does Unsupported not wait?"
178// should not have to find it inside a 10 000-line file.
179#[cfg(all(test, feature = "alloc", not(feature = "rmw-cffi")))]
180mod graph_wait_tests;
181
182// Flat re-exports so users write `executor::Executor` etc.
183#[cfg(any(has_rmw, test))]
184pub use action::{
185    ActionClientRawHandle, ActionServerHandle, ActionServerRawHandle, RawActionClientSpec,
186    RawActionServerSpec,
187};
188#[cfg(any(has_rmw, test))]
189pub use action_core::{ActionClientCore, ActionServerCore, RawActiveGoal, action_channel_type};
190// phase-430 W4 — DEFINED in `crate::timer` (ungated) and re-exported here, so
191// `nros_node::executor::TimerClockSource` keeps resolving for every caller
192// phase-425 wrote while the declarative metadata layer, which builds with no
193// transport, can name the same enum instead of inventing a second one.
194pub use crate::timer::{TimerCallInfo, TimerClockSource};
195#[cfg(any(has_rmw, test))]
196pub use arena::TimerOverrunPolicy;
197#[cfg(any(has_rmw, test))]
198pub use handles::*;
199#[cfg(any(has_rmw, test))]
200// `Node` joined this line in 2026-09-12 (issue 1351). It was the only one of
201// the three that `mod node` kept to itself, and it was not a smaller surface for
202// it: `Executor::node_mut` is `pub` and RETURNS a `Node`, the `nros` crate's
203// own first doc example is `executor.node_mut(node).create_publisher::<Int32>(…)`,
204// and 15 in-tree binaries call its methods. What the missing `pub use` bought
205// was that the type had no PATH — a user could call all ~25 methods and could
206// not write `fn setup(ctx: &mut Node)` to factor two of them out, and the
207// Rust parity extractor (which walks the umbrella's reachable surface) had never
208// produced a single row for any of them.
209pub use node::{CallbackGroup, Node, NodeHandle};
210#[cfg(any(has_rmw, test))]
211pub use node_record::{NodeBuilder, NodeId, NodeRecord};
212#[cfg(any(has_rmw, test))]
213pub use spin::Executor;
214// phase-509 P9b item 2 -- a band worker over a shared executor.
215#[cfg(any(has_rmw, test))]
216pub use scheduler::{Band, BandWaitFn, BandWaiter, BandWorker, WorkerWakeFn};
217// phase-436 — the wake-source seam's types. `Executor::last_park` RETURNS a
218// `WakeSourceId` and `register_wake_source` / `set_park_primitive` TAKE the two
219// fn-pointer types, so all four are already public API; without these a caller
220// outside the crate could receive a value it cannot name or match on.
221pub use launch_remap::{BadLaunchRemap, LaunchRemap, launch_remaps, set_launch_remaps};
222pub use session_props::{
223    BadSessionProperties, MAX_SESSION_PROPERTIES, SessionProperty, lent_session_properties,
224    session_properties, set_session_properties, with_session_properties,
225};
226#[cfg(any(has_rmw, test))]
227pub use spin::SessionHandle;
228#[cfg(all(any(has_rmw, test), feature = "rmw-cffi"))]
229pub use spin::SessionSpec;
230#[cfg(any(has_rmw, test))]
231pub use spin::{
232    MAX_WAKE_SOURCES, NextDeadlineFn, PARK_EXPIRED, PARK_SIGNALLED, PARK_YIELDED, ParkUntilFn,
233    RemapRefused, WakeHookFn, WakeSourceId,
234};
235#[cfg(any(has_rmw, test))]
236pub use storage::{
237    ExecutorInlineStorage, ExecutorSizing, INLINE_BACKING_U64S, INLINE_SIZING, RegionUnit,
238    RegionUnits, executor_storage_layout, executor_storage_layout_with, executor_storage_u64_len,
239    levels_backing_bytes, levels_executor_sizing, sched_task_backing_bytes,
240    sched_task_executor_sizing, sched_task_sizing,
241};
242pub use types::*;