diff --git a/sfizz/FilePool.cpp b/sfizz/FilePool.cpp index e10377f3..9acec5e7 100644 --- a/sfizz/FilePool.cpp +++ b/sfizz/FilePool.cpp @@ -145,16 +145,17 @@ void sfz::FilePool::loadingThread() noexcept void sfz::FilePool::garbageThread() noexcept { while (!quitThread) { + fileHandleMutex.lock(); for (auto handle = fileHandles.begin(); handle < fileHandles.end();) { if (handle->use_count() == 1) { handle->reset(); - std::lock_guard guard { fileHandleMutex }; std::iter_swap(handle, fileHandles.end() - 1); fileHandles.pop_back(); } else { handle++; } } + fileHandleMutex.unlock(); std::this_thread::sleep_for(200ms); } } diff --git a/sfizz/FilePool.h b/sfizz/FilePool.h index 5c0c41db..eee11e7a 100644 --- a/sfizz/FilePool.h +++ b/sfizz/FilePool.h @@ -72,11 +72,11 @@ private: void loadingThread() noexcept; void garbageThread() noexcept; bool quitThread { false }; + std::mutex fileHandleMutex; + std::vector>> fileHandles; + absl::flat_hash_map>> preloadedData; std::thread fileLoadingThread { &FilePool::loadingThread, this }; std::thread garbageCollectionThread { &FilePool::garbageThread, this }; - std::vector>> fileHandles; - std::mutex fileHandleMutex; - absl::flat_hash_map>> preloadedData; LEAK_DETECTOR(FilePool); }; } diff --git a/sfizz/Synth.cpp b/sfizz/Synth.cpp index a2e61aba..cc3c2b04 100644 --- a/sfizz/Synth.cpp +++ b/sfizz/Synth.cpp @@ -108,6 +108,14 @@ void sfz::Synth::buildRegion(const std::vector& regionOpcodes) void sfz::Synth::clear() { + for (auto &voice: voices) + voice->reset(); + for (auto& list: noteActivationLists) + list.clear(); + for (auto& list: ccActivationLists) + list.clear(); + regions.clear(); + filePool.clear(); hasGlobal = false; hasControl = false; numGroups = 0; @@ -121,8 +129,6 @@ void sfz::Synth::clear() globalOpcodes.clear(); masterOpcodes.clear(); groupOpcodes.clear(); - regions.clear(); - filePool.clear(); } void sfz::Synth::handleGlobalOpcodes(const std::vector& members)