Skip to main content

aion/runtime/
config.rs

1//! Builder-supplied scheduler configuration for the embedded runtime.
2
3use std::time::Duration;
4
5/// Configuration used when constructing the embedded BEAM runtime.
6#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
7pub struct RuntimeConfig {
8    /// Optional scheduler thread count supplied by the engine builder.
9    ///
10    /// `None` is passed through to beamr so the embedded runtime applies its own
11    /// runtime-aware default.
12    pub thread_count: Option<usize>,
13
14    /// Bounded readiness and retry policy for live signal mailbox delivery.
15    pub signal_delivery: SignalDeliveryConfig,
16}
17
18/// Bounded signal delivery retry policy supplied by engine configuration.
19#[derive(Clone, Copy, Debug, Eq, PartialEq)]
20pub struct SignalDeliveryConfig {
21    /// Maximum time to wait for a just-spawned process body to materialize.
22    pub ready_timeout: Duration,
23
24    /// Maximum number of mailbox enqueue attempts after the ready gate.
25    pub max_enqueue_attempts: u32,
26
27    /// Initial sleep between failed enqueue attempts.
28    pub initial_backoff: Duration,
29
30    /// Upper bound for exponential backoff between enqueue attempts.
31    pub max_backoff: Duration,
32}
33
34impl Default for SignalDeliveryConfig {
35    fn default() -> Self {
36        Self::new(
37            Duration::from_millis(50),
38            8,
39            Duration::from_millis(1),
40            Duration::from_millis(8),
41        )
42    }
43}
44
45impl SignalDeliveryConfig {
46    /// Create an explicit signal delivery policy.
47    #[must_use]
48    pub const fn new(
49        ready_timeout: Duration,
50        max_enqueue_attempts: u32,
51        initial_backoff: Duration,
52        max_backoff: Duration,
53    ) -> Self {
54        Self {
55            ready_timeout,
56            max_enqueue_attempts,
57            initial_backoff,
58            max_backoff,
59        }
60    }
61}
62
63impl RuntimeConfig {
64    /// Create runtime configuration from the builder-supplied scheduler count.
65    #[must_use]
66    pub fn new(thread_count: Option<usize>) -> Self {
67        Self {
68            thread_count,
69            signal_delivery: SignalDeliveryConfig::default(),
70        }
71    }
72
73    /// Override the signal delivery retry policy.
74    #[must_use]
75    pub const fn with_signal_delivery(mut self, signal_delivery: SignalDeliveryConfig) -> Self {
76        self.signal_delivery = signal_delivery;
77        self
78    }
79}