From ed6d7578a573b5cf0bdf77eea1f47ee4a5a5c6be Mon Sep 17 00:00:00 2001 From: Benau Date: Wed, 27 Apr 2022 11:01:53 +0800 Subject: [PATCH] Avoid queue size race condition --- src/audio/sfx_manager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index 2dcf2c898..0d7fbdcb4 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -392,6 +392,7 @@ void SFXManager::mainLoop(void *obj) break; #endif } + bool empty_queue = me->m_sfx_commands.getData().empty(); ul.unlock(); PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("Execute", 0, 255, 0); @@ -462,9 +463,7 @@ void SFXManager::mainLoop(void *obj) current = NULL; PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("yield", 0, 0, 255); - // We access the size without lock, doesn't matter if we - // should get an incorrect value because of concurrent read/writes - if (me->m_sfx_commands.getData().size() == 0 && me->sfxAllowed()) + if (empty_queue && me->sfxAllowed()) { // Wait some time to let other threads run, then queue an // update event to keep music playing.