Implement popping from CircularQueue

This commit is contained in:
Billy Laws 2022-09-19 13:29:05 +01:00
parent 6d9dc9c6fb
commit 379b4f163d

View File

@ -76,6 +76,21 @@ namespace skyline {
} }
} }
Type Pop() {
std::unique_lock lock(productionMutex);
produceCondition.wait(lock, [this]() { return start != end; });
auto next{start + 1};
next = (next == reinterpret_cast<Type *>(vector.end().base())) ? reinterpret_cast<Type *>(vector.begin().base()) : next;
Type item{*next};
start = next;
if (start == end)
consumeCondition.notify_one();
return item;
}
void Push(const Type &item) { void Push(const Type &item) {
std::unique_lock lock(productionMutex); std::unique_lock lock(productionMutex);
auto next{end + 1}; auto next{end + 1};