From a048263fd6d01a5c8954933ac727545e4c502c0a Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 23 May 2023 02:42:35 -0500 Subject: [PATCH] chore: make use of std.atomic.spinLoopHint() --- src/core/emu.zig | 7 ++++++- src/platform.zig | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/emu.zig b/src/core/emu.zig index e009a67..94fb39d 100644 --- a/src/core/emu.zig +++ b/src/core/emu.zig @@ -140,6 +140,10 @@ fn audioSync(audio_sync: bool, stream: *SDL.SDL_AudioStream, is_buffer_full: *bo // If Busy is false, there's no need to sync here if (!still_full) return; + // TODO: Refactor!!!! + // while (SDL.SDL_AudioStreamAvailable(stream) > sample_size * max_buf_size >> 1) + // std.atomic.spinLoopHint(); + while (true) { still_full = SDL.SDL_AudioStreamAvailable(stream) > sample_size * max_buf_size >> 1; if (!audio_sync or !still_full) break; @@ -184,7 +188,8 @@ fn sleep(timer: *Timer, wake_time: u64) ?u64 { } fn spinLoop(timer: *Timer, wake_time: u64) void { - while (true) if (timer.read() > wake_time) break; + while (timer.read() < wake_time) + std.atomic.spinLoopHint(); } pub const EmuThing = struct { diff --git a/src/platform.zig b/src/platform.zig index 5922768..6a5ee6b 100644 --- a/src/platform.zig +++ b/src/platform.zig @@ -216,6 +216,7 @@ pub const Gui = struct { .Standard => blk: { const limit = 15; // TODO: What should this be? + // TODO: learn more about std.atomic.spinLoopHint(); for (0..limit) |_| { const message = channel.gui.pop() orelse continue;