feat(ui): add timeout for gui spinloop

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-05-23 02:23:50 -05:00
parent 21295b8d03
commit 2b9a479b96
1 changed files with 17 additions and 7 deletions

View File

@ -134,6 +134,7 @@ pub const Gui = struct {
switch (event.type) { switch (event.type) {
SDL.SDL_QUIT => break :emu_loop, SDL.SDL_QUIT => break :emu_loop,
SDL.SDL_KEYDOWN => { SDL.SDL_KEYDOWN => {
// TODO: Make use of compare_and_xor?
const key_code = event.key.keysym.sym; const key_code = event.key.keysym.sym;
var keyinput = cpu.bus.io.keyinput.load(.Monotonic); var keyinput = cpu.bus.io.keyinput.load(.Monotonic);
@ -154,6 +155,7 @@ pub const Gui = struct {
cpu.bus.io.keyinput.store(keyinput.raw, .Monotonic); cpu.bus.io.keyinput.store(keyinput.raw, .Monotonic);
}, },
SDL.SDL_KEYUP => { SDL.SDL_KEYUP => {
// TODO: Make use of compare_and_xor?
const key_code = event.key.keysym.sym; const key_code = event.key.keysym.sym;
var keyinput = cpu.bus.io.keyinput.load(.Monotonic); var keyinput = cpu.bus.io.keyinput.load(.Monotonic);
@ -204,19 +206,27 @@ pub const Gui = struct {
self.state.emulation = .Inactive; self.state.emulation = .Inactive;
}, },
}, },
.Active => { .Active => skip_draw: {
const is_std = mode == .Standard; const is_std = mode == .Standard;
if (is_std) channel.emu.push(.Pause); if (is_std) channel.emu.push(.Pause);
defer if (is_std) channel.emu.push(.Resume); defer if (is_std) channel.emu.push(.Resume);
switch (mode) { switch (mode) {
.Standard => { .Standard => blk: {
// TODO: add timeout const limit = 15; // TODO: What should this be?
while (true) switch (channel.gui.pop() orelse continue) {
.Paused => break, for (0..limit) |_| {
.Quit => unreachable, // only signaled in debug mode const message = channel.gui.pop() orelse continue;
};
switch (message) {
.Paused => break :blk,
.Quit => unreachable,
}
}
log.info("timed out waiting for emu thread to pause (limit: {})", .{limit});
break :skip_draw;
}, },
.Debug => blk: { .Debug => blk: {
switch (channel.gui.pop() orelse break :blk) { switch (channel.gui.pop() orelse break :blk) {