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
//! Weave-internal helpers for coroutine lifecycle.
//!
//! - `cleanup_strand`: decrement `ACTIVE_STRANDS` and signal shutdown when the
//! last strand completes. Called by spawn (normal completion) and yield
//! (unrecoverable error path).
//! - `block_forever`: block the current coroutine without panicking, used when
//! an `extern "C"` weave function hits an unrecoverable error and cannot
//! return or panic safely.
use mpmc;
/// Block the current coroutine forever without panicking.
///
/// This is used when an unrecoverable error occurs in an extern "C" function.
/// We can't panic (UB across FFI) and we can't return (invalid state), so we
/// clean up and block forever. The coroutine is already marked as completed
/// via `cleanup_strand()`, so the program can still terminate normally.
///
/// # Safety
/// Must only be called from within a spawned coroutine, never from the main thread.
///
/// # Implementation
/// Uses May's coroutine-aware channel blocking. We keep the sender alive so that
/// `recv()` blocks the coroutine (not the OS thread) indefinitely. This is critical
/// because `std::thread::park()` would block the OS thread and starve all other
/// coroutines on that thread, potentially deadlocking the scheduler.
pub !
/// Helper to clean up strand on exit
pub