fix(gui): fix shutdown hang

This commit is contained in:
CJ van den Berg 2026-03-30 20:58:52 +02:00
parent 875c42ad9e
commit 273be78055
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -40,6 +40,7 @@ var font_size_px: u16 = 16;
var font_name_buf: [256]u8 = undefined; var font_name_buf: [256]u8 = undefined;
var font_name_len: usize = 0; var font_name_len: usize = 0;
var font_dirty: std.atomic.Value(bool) = .init(true); var font_dirty: std.atomic.Value(bool) = .init(true);
var stop_requested: std.atomic.Value(bool) = .init(false);
// Current font written and read only from the wio thread (after gpu.init). // Current font written and read only from the wio thread (after gpu.init).
var wio_font: gpu.Font = .{ .cell_size = .{ .x = 8, .y = 16 } }; var wio_font: gpu.Font = .{ .cell_size = .{ .x = 8, .y = 16 } };
@ -49,12 +50,12 @@ var wio_font: gpu.Font = .{ .cell_size = .{ .x = 8, .y = 16 } };
pub fn start() !std.Thread { pub fn start() !std.Thread {
tui_pid = thespian.self_pid().clone(); tui_pid = thespian.self_pid().clone();
font_name_len = 0; font_name_len = 0;
stop_requested.store(false, .release);
return std.Thread.spawn(.{}, wioLoop, .{}); return std.Thread.spawn(.{}, wioLoop, .{});
} }
pub fn stop() void { pub fn stop() void {
// The wio thread will stop when the window's .close event arrives. stop_requested.store(true, .release);
// We can't easily interrupt wio.wait() from outside without cancelWait.
wio.cancelWait(); wio.cancelWait();
} }
@ -232,6 +233,7 @@ fn wioLoop() void {
while (running) { while (running) {
wio.wait(.{}); wio.wait(.{});
if (stop_requested.load(.acquire)) break;
// Reload font if settings changed (font_dirty set by TUI thread). // Reload font if settings changed (font_dirty set by TUI thread).
maybeReloadFont(win_size, &state, &cell_width, &cell_height); maybeReloadFont(win_size, &state, &cell_width, &cell_height);