Avoid queue size race condition

This commit is contained in:
Benau 2022-04-27 11:01:53 +08:00
parent 96cd140c62
commit ed6d7578a5

View File

@ -392,6 +392,7 @@ void SFXManager::mainLoop(void *obj)
break; break;
#endif #endif
} }
bool empty_queue = me->m_sfx_commands.getData().empty();
ul.unlock(); ul.unlock();
PROFILER_POP_CPU_MARKER(); PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("Execute", 0, 255, 0); PROFILER_PUSH_CPU_MARKER("Execute", 0, 255, 0);
@ -462,9 +463,7 @@ void SFXManager::mainLoop(void *obj)
current = NULL; current = NULL;
PROFILER_POP_CPU_MARKER(); PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("yield", 0, 0, 255); PROFILER_PUSH_CPU_MARKER("yield", 0, 0, 255);
// We access the size without lock, doesn't matter if we if (empty_queue && me->sfxAllowed())
// should get an incorrect value because of concurrent read/writes
if (me->m_sfx_commands.getData().size() == 0 && me->sfxAllowed())
{ {
// Wait some time to let other threads run, then queue an // Wait some time to let other threads run, then queue an
// update event to keep music playing. // update event to keep music playing.