Replace the filled promise queue busy wait with semaphore

This commit is contained in:
Jean Pierre Cimalando 2020-06-23 04:03:35 +02:00
parent 26d63a92f0
commit b0c8495f6c
2 changed files with 6 additions and 5 deletions

View file

@ -415,10 +415,8 @@ void sfz::FilePool::loadingThread() noexcept
threadsLoading--;
while (!filledPromiseQueue.try_push(promise)) {
DBG("[sfizz] Error enqueuing the promise for " << promise->fileId << " in the filledPromiseQueue");
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
semFilledPromiseQueueAvailable.wait();
filledPromiseQueue.push(promise);
promise.reset();
} while (1);
@ -447,8 +445,10 @@ void sfz::FilePool::cleanupPromises() noexcept
// Remove the promises from the filled queue and put them in a linear
// storage
FilePromisePtr promise;
while (filledPromiseQueue.try_pop(promise))
while (filledPromiseQueue.try_pop(promise)) {
semFilledPromiseQueueAvailable.post();
temporaryFilePromises.push_back(promise);
}
auto promiseUsedOnce = [](FilePromisePtr& p) { return p.use_count() == 1; };
auto moveToClear = [&](FilePromisePtr& p) { return promisesToClear.push_back(p); };

View file

@ -268,6 +268,7 @@ private:
atomic_queue::AtomicQueue2<FilePromisePtr, config::maxVoices> promiseQueue;
atomic_queue::AtomicQueue2<FilePromisePtr, config::maxVoices> filledPromiseQueue;
RTSemaphore semFilledPromiseQueueAvailable { config::maxVoices };
uint32_t preloadSize { config::preloadSize };
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
// Signals