The spinlocking on FilePool::emptyQueue is now integrated in the function

This commit is contained in:
Paul Ferrand 2019-12-01 12:16:35 +01:00
parent 35d334bb73
commit 97a5d5ce90
3 changed files with 14 additions and 7 deletions

View file

@ -174,3 +174,10 @@ void sfz::FilePool::clear()
// Pop the queue // Pop the queue
} }
} }
void sfz::FilePool::emptyFileLoadingQueue() noexcept
{
emptyQueue = true;
while (emptyQueue)
std::this_thread::sleep_for(1ms);
}

View file

@ -113,8 +113,13 @@ public:
* *
*/ */
void clear(); void clear();
void emptyFileLoadingQueue() noexcept { emptyQueue = true; } /**
bool shouldEmptyQueue() const noexcept { return emptyQueue; } * @brief Empty the file loading queue. This function will lock and wait
* for the background thread to finish its business, so don't call it from
* the audio thread.
*
*/
void emptyFileLoadingQueue() noexcept;
private: private:
fs::path rootDirectory; fs::path rootDirectory;
struct FileLoadingInformation { struct FileLoadingInformation {

View file

@ -533,12 +533,7 @@ void sfz::Synth::resetVoices(int numVoices)
std::this_thread::sleep_for(1ms); std::this_thread::sleep_for(1ms);
} }
// Empty the file pool loading queue and spinlock on it
filePool.emptyFileLoadingQueue(); filePool.emptyFileLoadingQueue();
while (filePool.shouldEmptyQueue()) {
std::this_thread::sleep_for(1ms);
}
voices.clear(); voices.clear();
for (int i = 0; i < numVoices; ++i) for (int i = 0; i < numVoices; ++i)
voices.push_back(std::make_unique<Voice>(midiState)); voices.push_back(std::make_unique<Voice>(midiState));