From 95ecd0eed1b72d3178d696d2b13cedb794fd3641 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 10 Feb 2015 09:22:23 +1100 Subject: [PATCH] Let the audio thread run 'all the time' by sending itself an update package after the queue is empty. --- src/audio/sfx_manager.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index 5f9910e54..b8bf46585 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -355,6 +355,15 @@ void* SFXManager::mainLoop(void *obj) } delete current; current = NULL; + // 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) + { + // Wait some time to let other threads run, then queue an + // update event to keep music playing. + StkTime::sleep(1); + me->queue(SFX_UPDATE, (SFXBase*)NULL, 0.01f); + } me->m_sfx_commands.lock(); } // while