Replace the filled promise queue busy wait with semaphore
This commit is contained in:
parent
26d63a92f0
commit
b0c8495f6c
2 changed files with 6 additions and 5 deletions
|
|
@ -415,10 +415,8 @@ void sfz::FilePool::loadingThread() noexcept
|
||||||
|
|
||||||
threadsLoading--;
|
threadsLoading--;
|
||||||
|
|
||||||
while (!filledPromiseQueue.try_push(promise)) {
|
semFilledPromiseQueueAvailable.wait();
|
||||||
DBG("[sfizz] Error enqueuing the promise for " << promise->fileId << " in the filledPromiseQueue");
|
filledPromiseQueue.push(promise);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
promise.reset();
|
promise.reset();
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
@ -447,8 +445,10 @@ void sfz::FilePool::cleanupPromises() noexcept
|
||||||
// Remove the promises from the filled queue and put them in a linear
|
// Remove the promises from the filled queue and put them in a linear
|
||||||
// storage
|
// storage
|
||||||
FilePromisePtr promise;
|
FilePromisePtr promise;
|
||||||
while (filledPromiseQueue.try_pop(promise))
|
while (filledPromiseQueue.try_pop(promise)) {
|
||||||
|
semFilledPromiseQueueAvailable.post();
|
||||||
temporaryFilePromises.push_back(promise);
|
temporaryFilePromises.push_back(promise);
|
||||||
|
}
|
||||||
|
|
||||||
auto promiseUsedOnce = [](FilePromisePtr& p) { return p.use_count() == 1; };
|
auto promiseUsedOnce = [](FilePromisePtr& p) { return p.use_count() == 1; };
|
||||||
auto moveToClear = [&](FilePromisePtr& p) { return promisesToClear.push_back(p); };
|
auto moveToClear = [&](FilePromisePtr& p) { return promisesToClear.push_back(p); };
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,7 @@ private:
|
||||||
|
|
||||||
atomic_queue::AtomicQueue2<FilePromisePtr, config::maxVoices> promiseQueue;
|
atomic_queue::AtomicQueue2<FilePromisePtr, config::maxVoices> promiseQueue;
|
||||||
atomic_queue::AtomicQueue2<FilePromisePtr, config::maxVoices> filledPromiseQueue;
|
atomic_queue::AtomicQueue2<FilePromisePtr, config::maxVoices> filledPromiseQueue;
|
||||||
|
RTSemaphore semFilledPromiseQueueAvailable { config::maxVoices };
|
||||||
uint32_t preloadSize { config::preloadSize };
|
uint32_t preloadSize { config::preloadSize };
|
||||||
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
|
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
|
||||||
// Signals
|
// Signals
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue