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
//! Critical sections: the one primitive every ring mutation depends on.
//!
//! Masking is deliberately *not* uniform across backends, because the right
//! mechanism genuinely differs:
//!
//! | Backend | `critical_enter` |
//! |------------|---------------------------------------------------------|
//! | Cortex-M | `cpsid i` + save/restore `PRIMASK` |
//! | POSIX | `sigprocmask` blocking `SIGALRM` (a *pending* SIGALRM is delivered as soon as the section exits, so ticks are never lost) |
//! | Win32 | recursive kernel spinlock (owner thread id + depth), because the tick thread really is a second thread |
//!
//! Critical sections must be **short and non-blocking**: on the host the tick
//! thread waits for the lock, so a task that blocked while holding it would
//! stall the scheduler.
use crateCriticalToken;
/// RAII guard for a critical section. Restores the previous interrupt state /
/// drops the lock on scope exit (including on early return).
/// Enter a critical section. Nestable on every backend.
/// Run `f` with preemption disabled, returning its result.