7#include <condition_variable>
37 std::unique_lock<std::mutex> lock(mutex_);
38 not_full_.wait(lock, [
this] {
return closed_ || items_.size() < capacity_; });
42 items_.push_back(std::move(item));
44 not_empty_.notify_one();
51 [[nodiscard]] std::optional<T>
pop() {
52 std::unique_lock<std::mutex> lock(mutex_);
53 not_empty_.wait(lock, [
this] {
return closed_ || !items_.empty(); });
57 T item = std::move(items_.front());
60 not_full_.notify_one();
67 std::lock_guard<std::mutex> lock(mutex_);
70 not_empty_.notify_all();
71 not_full_.notify_all();
78 std::condition_variable not_full_;
79 std::condition_variable not_empty_;
Fixed-capacity thread-safe queue with blocking push/pop – the bounded buffer between pulsatrix data-p...
Definition bounded_queue.hpp:26
void close()
Signals no more pushes will occur; unblocks every waiting push()/pop().
Definition bounded_queue.hpp:65
void push(T item)
Pushes an item, blocking while the queue is full.
Definition bounded_queue.hpp:36
std::optional< T > pop()
Pops the next item, blocking while the queue is empty and not closed.
Definition bounded_queue.hpp:51
BoundedQueue(size_t capacity)
Definition bounded_queue.hpp:28
Definition acquisition_functions.hpp:16