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
//! Cross-thread UI wake and callback dispatch.
//!
//! Layer 1 — EventLoopProxy globalisation:
//! On startup, `App::run()` stores a winit `EventLoopProxy` so that any
//! thread can call [`wake_ui()`] to wake the event loop.
//!
//! Layer 2 — `run_on_ui` / `spawn_background` (see [`crate::task`]):
//! [`run_on_ui`] pushes a `Send + 'static` closure into a global queue
//! and wakes the UI. The closure is drained and executed on the UI
//! thread during the next event-loop cycle. This is how background
//! threads safely update signals without touching `thread_local!` state.
//!
//! Layer 3 — automatic wake dedup:
//! An [`AtomicBool`] keeps track of whether a `wake_up()` call is already
//! in-flight. Repeated calls to [`wake_ui()`] are no-ops until the UI
//! thread drains the pending work, avoiding `wake_up()` storms.
use ;
use ;
use EventLoopProxy;
/// The singleton winit proxy. Set once by `App::run()` before the event
/// loop starts and never cleared.
static UI_PROXY: = new;
/// Set by [`wake_ui`] to `true` when a wake-up has been requested but not
/// yet consumed. Switched back to `false` by [`drain_ui_queue`].
static WAKE_SENT: AtomicBool = new;
/// Pending closures enqueued via [`run_on_ui`] from any thread.
static UI_QUEUE: = new;
// ── Initialisation ─────────────────────────────────────────────────
/// Called once by `App::run()`. Safe to call multiple times; subsequent
/// calls are ignored.
pub
// ── Public API ─────────────────────────────────────────────────────
/// Wake the event loop from any thread.
///
/// Idempotent — if a wake-up is already pending the call is a no-op.
/// This is the primitive that makes cross-thread signal updates
/// responsive; call it after pushing work via [`run_on_ui`].
///
/// See also [`run_on_ui`] which calls `wake_ui()` automatically.
/// Push a closure onto the global UI queue and wake the event loop.
///
/// The closure will be executed on the UI thread during the next
/// event-loop drain cycle (see `drain_ui_queue`). All of the
/// framework's `thread_local!` state is available to the closure.
///
/// # Example
///
/// ```ignore
/// std::thread::spawn(move || {
/// let data = compute();
/// burin::platform::wake::run_on_ui(move || {
/// my_signal.set(data); // safe — we are on the UI thread
/// });
/// });
/// ```
// ── Internal: drain (called from the event loop) ───────────────────
/// Drain all pending `run_on_ui` closures on the UI thread.
///
/// Called once per event-loop cycle from `App::about_to_wait`, before
/// `flush_scheduler.drain()`. Clears the `WAKE_SENT` flag so that
/// subsequent `wake_ui()` calls can trigger a new wake-up cycle.
pub
/// True if the global UI queue holds pending work.
pub
/// Reset global state (for parallel test isolation).