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
// SPDX-License-Identifier: MIT OR Apache-2.0
//! 2026-10-03: Parks the scheduler thread when it reaches a chosen model call (before the call's
//! trace line is recorded), so a test can act at that exact point of the loop (close the inbox,
//! say) and then let it go on.
//!
//! Owner: scheduler.
//! Invariants: an armed park fires once, on the first recorded line that starts with its
//! prefix; an unarmed one never blocks.
use std::sync::{Condvar, Mutex};
#[derive(Default)]
pub(super) struct LinePark {
state: Mutex<ParkState>,
cv: Condvar,
}
#[derive(Default)]
struct ParkState {
prefix: Option<String>,
parked: bool,
released: bool,
}
impl LinePark {
/// 2026-10-03: Park on the first recorded line starting with `prefix`.
pub fn arm(&self, prefix: &str) {
self.state.lock().unwrap().prefix = Some(prefix.to_string());
}
/// 2026-10-03: Called on the scheduler thread with each line about to be recorded.
pub fn check(&self, line: &str) {
let mut g = self.state.lock().unwrap();
if !g.prefix.as_deref().is_some_and(|p| line.starts_with(p)) {
return;
}
g.prefix = None;
g.parked = true;
self.cv.notify_all();
while !g.released {
g = self.cv.wait(g).unwrap();
}
}
/// 2026-10-03: Block until the loop is parked.
pub fn wait_parked(&self) {
let mut g = self.state.lock().unwrap();
while !g.parked {
g = self.cv.wait(g).unwrap();
}
}
pub fn release(&self) {
self.state.lock().unwrap().released = true;
self.cv.notify_all();
}
}