1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//! Runtime state and scheduling.
//!
//! This module contains the core runtime machinery:
//!
//! - [`config`]: Runtime configuration types
//! - [`builder`]: Runtime builder and handles
//! - [`state`]: Global runtime state (Σ = {regions, tasks, obligations, now})
//! - [`scheduler`]: Three-lane priority scheduler
//! - [`stored_task`]: Type-erased future storage
//! - [`task_handle`]: TaskHandle for awaiting spawned task results
//! - [`waker`]: Waker implementation with deduplication
//! - [`timer`]: Timer heap for deadline management
//! - [`deadline_monitor`]: Deadline monitoring for approaching timeouts
//! - [`reactor`]: I/O reactor abstraction
//! - [`io_driver`]: Reactor driver that dispatches readiness to wakers
//! - [`region_heap`]: Region-owned heap allocator with quiescent reclamation
//!
//! # Runtime Builder
//!
//! Asupersync configures the runtime with a fluent, move-based builder API.
//! Each builder method consumes `self` and returns an updated builder, enabling
//! ergonomic chaining without borrowing hazards.
//!
//! ## Quick Start
//!
//! ```ignore
//! use asupersync::runtime::RuntimeBuilder;
//!
//! let runtime = RuntimeBuilder::new().build()?;
//! runtime.block_on(async { /* your async work */ });
//! ```
//!
//! ## Single-Threaded (Deterministic)
//!
//! ```ignore
//! use asupersync::runtime::RuntimeBuilder;
//!
//! let runtime = RuntimeBuilder::current_thread().build()?;
//! runtime.block_on(async { /* deterministic tests */ });
//! ```
//!
//! ## High-Throughput Server
//!
//! ```ignore
//! use asupersync::runtime::RuntimeBuilder;
//!
//! let runtime = RuntimeBuilder::high_throughput()
//! .global_queue_limit(65_536)
//! .blocking_threads(4, 64)
//! .build()?;
//! ```
//!
//! ## Low-Latency Workloads
//!
//! ```ignore
//! use asupersync::runtime::RuntimeBuilder;
//! use std::time::Duration;
//!
//! let runtime = RuntimeBuilder::low_latency()
//! .poll_budget(16)
//! .deadline_monitoring(|m| {
//! m.enabled(true)
//! .check_interval(Duration::from_millis(5))
//! .warning_threshold_fraction(0.2)
//! })
//! .build()?;
//! ```
//!
//! ## Config File + Environment Overrides
//!
//! ```ignore
//! use asupersync::runtime::RuntimeBuilder;
//!
//! // Requires the `config-file` feature.
//! let runtime = RuntimeBuilder::from_toml("config/runtime.toml")?
//! .with_env_overrides()?
//! .build()?;
//! ```
//!
//! # Error Handling
//!
//! ```ignore
//! use asupersync::runtime::RuntimeBuilder;
//!
//! // Requires the `config-file` feature.
//! let result = RuntimeBuilder::from_toml_str("not valid {{{");
//! assert!(result.is_err());
//! ```
//!
//! # Migration Guide (RuntimeConfig → RuntimeBuilder)
//!
//! ```ignore
//! use asupersync::runtime::{Runtime, RuntimeBuilder, RuntimeConfig};
//!
//! // Old style: build a config directly.
//! let mut config = RuntimeConfig::default();
//! config.worker_threads = 4;
//! let runtime = Runtime::with_config(config)?;
//!
//! // New style: builder chain.
//! let runtime = RuntimeBuilder::new()
//! .worker_threads(4)
//! .build()?;
//! ```
//!
//! # Configuration Reference (Defaults + Notes)
//!
//! - `worker_threads`: default = available parallelism (min 1). Higher throughput, more CPU use.
//! - `thread_stack_size`: default = 2 MiB. Larger stack increases memory per worker.
//! - `thread_name_prefix`: default = `asupersync-worker`. Improves diagnostics.
//! - `global_queue_limit`: default = 0 (unbounded). Lower values add backpressure.
//! - `steal_batch_size`: default = 16. Larger favors throughput; smaller favors latency.
//! - `blocking_threads(min, max)`: default = 0..0. Max is clamped to be >= min.
//! - `enable_parking`: default = true. Disabling reduces wake latency at CPU cost.
//! - `poll_budget`: default = 128. Lower for fairness, higher for throughput.
//! - `root_region_limits`: default = None. Admission limits applied to root region.
//! - `on_thread_start/stop`: lifecycle hooks; keep work minimal to avoid jitter.
//! - `metrics(...)`: default = NoOp. Custom providers add instrumentation overhead.
//! - `deadline_monitoring(...)`: disabled by default; enables warning callbacks.
/// Proof-carrying decision-plane kernel for runtime controllers.
/// Async wrapper for blocking pool operations.
/// Yield points for cooperative multitasking.
/// Thread-local storage for non-Send local tasks.
///
/// Local tasks are pinned to the worker thread that created them. They are
/// stored in TLS so only that worker can poll them.
pub use crateRegionLimits;
pub use crate;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use IoOp;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Scheduler;
pub use ;
pub use ;
pub use ;
pub use ;
pub use StoredTask;
pub use ;
pub use TaskTable;
pub use yield_now;