From e405d438ccfc8afb20e291c312262af7a61f9cd1 Mon Sep 17 00:00:00 2001 From: geneotech Date: Fri, 15 Mar 2024 19:45:59 +0100 Subject: [PATCH] MASSIVE CRASHFIX! Remove audio deadlock. --- src/augs/audio/audio_command_buffers.h | 14 ++++++++++---- src/augs/templates/thread_pool.h | 10 +++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/augs/audio/audio_command_buffers.h b/src/augs/audio/audio_command_buffers.h index ba4e362be..c4789ba1a 100644 --- a/src/augs/audio/audio_command_buffers.h +++ b/src/augs/audio/audio_command_buffers.h @@ -8,7 +8,7 @@ #include "augs/audio/audio_command.h" #include "augs/audio/audio_backend.h" -static constexpr int num_audio_buffers_v = 4; +static constexpr int num_audio_buffers_v = 10; namespace augs { class audio_command_buffers { @@ -73,10 +73,16 @@ namespace augs { } void report_completion() { - auto lk = lock_queue(); - read_index = next_to(read_index); + bool finished = false; + + { + auto lk = lock_queue(); + read_index = next_to(read_index); + + finished = has_finished(); + } - if (has_finished()) { + if (finished) { for_completion.notify_all(); pool_to_help_when_idle.help_until_no_tasks(); } diff --git a/src/augs/templates/thread_pool.h b/src/augs/templates/thread_pool.h index b63dcc7dc..4394cb3d5 100644 --- a/src/augs/templates/thread_pool.h +++ b/src/augs/templates/thread_pool.h @@ -32,13 +32,17 @@ namespace augs { } void register_completion() { + bool completed = false; + { auto lock = lock_completion(); ++tasks_completed; - if (tasks_completed == tasks_posted) { - completion_variable.notify_all(); - } + completed = tasks_completed == tasks_posted; + } + + if (completed) { + completion_variable.notify_all(); } }