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.

Declared at: include/double_buffered_queue.h:15

Template Parameters

T

Member Variables

struct write_end m_write
struct read_end m_read

Member Function Overview

Member Functions

bool empty() const

Description

Returns true if a call to pop_all would have returned an empty vector.

Declared at: include/double_buffered_queue.h:43


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

Declared at: include/double_buffered_queue.h:31


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.

Declared at: include/double_buffered_queue.h:18

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.

Declared at: include/double_buffered_queue.h:46