From 194fe8a451303e379f66632aa3f06cf610f2a208 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 13 May 2024 07:54:14 +0200 Subject: [PATCH] Audio: fix potential exit deadlock Signed-off-by: Stephen Gutekanst --- src/Audio.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Audio.zig b/src/Audio.zig index dc1e5d3e..f422cf65 100644 --- a/src/Audio.zig +++ b/src/Audio.zig @@ -245,6 +245,14 @@ fn writeFn(audio_opaque: ?*anyopaque, output: []u8) void { break :l; } audio.state().output_mu.unlock(); + + // Handle potential exit + audio.state().running_mu.lock(); + if (!audio.state().running) { + audio.state().running_mu.unlock(); + @memset(output, 0); + return; + } } } if (read_slice.len > output.len) {