Skip to main content

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

struct write_end m_write
struct read_end m_read

Member Function Overview

Member Functions

[[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)

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()

Description

After this function returns, the result of pop_all is non-empty as long as there is only a single reader thread.