Move the lock guard

This commit is contained in:
Paul Ferrand 2020-10-15 15:58:08 +02:00 committed by GitHub
parent a5647ab339
commit 67af16f0e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -476,13 +476,14 @@ void sfz::FilePool::dispatchingJob() noexcept
continue;
}
std::lock_guard<SpinMutex> guard { loadingJobsMutex };
if (filesToLoad.try_pop(queuedData)) {
loadingJobs.push_back(
threadPool.enqueue([this](const QueuedFileData& data) { loadingJob(data); }, queuedData));
}
// Clear finished jobs
std::lock_guard<SpinMutex> guard { loadingJobsMutex };
swapAndPopAll(loadingJobs, [](std::future<void>& future) {
return future.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
});