class double_buffered_queue
Declaration
template <typename T>
class double_buffered_queue { /* full declaration omitted */ };
Description
(Thread-safe) multi-producer single-consumer queue that uses double-buffering to avoid lock contention and keep dequeueing latency as low as possible.
Template Parameters
- T
Member Variables
Member Function Overview
- pop_all() → [[nodiscard]] std::vector<T> &
- push(T v) → void
- wait_while_empty() → void
Member Functions
¶[[nodiscard]] std::vector<T>& pop_all()
[[nodiscard]] std::vector<T>& pop_all()
Description
Returns all elements pushed to the queue since the last pop_all
. The returned reference is valid until the next call to pop_all
.
¶void push(T v)
void push(T v)
Description
Push a single element to the queue. Instead of frequently pushing multiple elements, consider using a vector as the element type.
Parameters
- T v
¶void wait_while_empty()
void wait_while_empty()
Description
After this function returns, the result of pop_all
is non-empty as long as there is only a single reader thread.