chore: make use of std.atomic.spinLoopHint()

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-05-23 02:42:35 -05:00
parent d9e09a9cbe
commit a048263fd6
2 changed files with 7 additions and 1 deletions

View File

@ -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 Busy is false, there's no need to sync here
if (!still_full) return; if (!still_full) return;
// TODO: Refactor!!!!
// while (SDL.SDL_AudioStreamAvailable(stream) > sample_size * max_buf_size >> 1)
// std.atomic.spinLoopHint();
while (true) { while (true) {
still_full = SDL.SDL_AudioStreamAvailable(stream) > sample_size * max_buf_size >> 1; still_full = SDL.SDL_AudioStreamAvailable(stream) > sample_size * max_buf_size >> 1;
if (!audio_sync or !still_full) break; 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 { 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 { pub const EmuThing = struct {

View File

@ -216,6 +216,7 @@ pub const Gui = struct {
.Standard => blk: { .Standard => blk: {
const limit = 15; // TODO: What should this be? const limit = 15; // TODO: What should this be?
// TODO: learn more about std.atomic.spinLoopHint();
for (0..limit) |_| { for (0..limit) |_| {
const message = channel.gui.pop() orelse continue; const message = channel.gui.pop() orelse continue;