Finer lock/unlock for the garbage collection mutex

This commit is contained in:
paulfd 2019-09-28 15:57:35 +02:00
parent ebdf758713
commit 9f24c2636e

View file

@ -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<std::mutex> guard { fileHandleMutex };
std::iter_swap(handle, fileHandles.end() - 1);
fileHandles.pop_back();
} else {
handle++;
}
}
fileHandleMutex.unlock();
std::this_thread::sleep_for(200ms);
}
}