diff --git a/src/departure.zig b/src/departure.zig index 5f59fb4..cf504e7 100644 --- a/src/departure.zig +++ b/src/departure.zig @@ -27,7 +27,14 @@ fn fetchThread(state: *AppState) !void { var curl = Curl.init() orelse return; defer curl.deinit(); - while (state.departure_screen_state.fetch_thread != null) { + while (true) { + { + state.departure_screen_state.mutex.lock(); + defer state.departure_screen_state.mutex.unlock(); + if (state.departure_screen_state.fetch_thread == null) { + break; + } + } var fetch_anyway = state.departure_screen_state.should_refresh; if (state.departure_screen_state.last_refresh_time + 30000 < std.time.milliTimestamp()) { fetch_anyway = true; @@ -635,6 +642,9 @@ pub fn render(state: *AppState) !void { switch (key) { rl.KEY_LEFT => { state.screen = .home; + ds.mutex.lock(); + defer ds.mutex.unlock(); + ds.fetch_thread = null; }, rl.KEY_R => { ds.should_refresh = true; @@ -666,7 +676,10 @@ pub fn render(state: *AppState) !void { { ds.mutex.lock(); - defer ds.mutex.unlock(); + defer { + ds.mutex.unlock(); + _ = std.Thread.yield() catch null; + } switch (ds.render_style) { .db1 => try draw_db1(state), .ns => try draw_ns(state), diff --git a/src/home.zig b/src/home.zig index 9b4e03e..18fe337 100644 --- a/src/home.zig +++ b/src/home.zig @@ -102,7 +102,10 @@ pub fn render(state: *AppState) !void { } state.home_screen_state.mutex.lock(); - defer state.home_screen_state.mutex.unlock(); + defer { + state.home_screen_state.mutex.unlock(); + _ = std.Thread.yield() catch null; + } while (raylib.GetKeyPressed()) |key| { switch (key) {