PosturePerfection
Public Member Functions
Buffer::Buffer< T > Class Template Reference

A synchronising buffer to be used as a communication mechanism between threads. More...

#include <pipeline.h>

Public Member Functions

 Buffer (bool *running_ptr, size_t max_size)
 Construct a new Buffer object. More...
 
void push (T frame)
 Push a frame to the queue. More...
 
bool try_push (T frame)
 Push a frame to the queue (doesn't block if queue is full) More...
 
PopResult< T > pop ()
 Pop the oldest element in the queue and return it. More...
 

Detailed Description

template<typename T>
class Buffer::Buffer< T >

A synchronising buffer to be used as a communication mechanism between threads.

The buffer ensures that elements are in order based on the element's id field. Attempting to push an element that is not next in line will block until the missing element has been pushed by a different thread. An object of this class may therefore be used to share the load at any stage in a pipeline between multiple threads without needing to worry about issues in the order of elements.

It is implemented as a circular buffer.

Template Parameters
TThe type for elements in the buffer. This must provide an id field that is a uint8_t.

Constructor & Destructor Documentation

◆ Buffer()

template<typename T >
Buffer::Buffer< T >::Buffer ( bool *  running_ptr,
size_t  max_size 
)
inlineexplicit

Construct a new Buffer object.

Parameters
running_ptrPointer to the Pipeline::Pipeline::running flag
max_sizeMaximum desired useable size of underlying memory

Member Function Documentation

◆ pop()

template<typename T >
PopResult<T> Buffer::Buffer< T >::pop ( )
inline

Pop the oldest element in the queue and return it.

Returns
PopResult<T> Oldest frame on the queue. Note: the valid flag of the result must be checked before use.

◆ push()

template<typename T >
void Buffer::Buffer< T >::push ( frame)
inline

Push a frame to the queue.

This blocks if the frame's ID is not the next in the series, until the missing frame has been pushed by another thread. Also blocks if the maximum size is reached, until elements are popped.

Template Parameters
frameFrame to be pushed to the queue

◆ try_push()

template<typename T >
bool Buffer::Buffer< T >::try_push ( frame)
inline

Push a frame to the queue (doesn't block if queue is full)

This blocks if the frame's ID is not the next in the series, until the missing frame has been pushed by another thread. It returns if the queue is full.

Parameters
frameFrame to be pushed to the queue
Returns
true If pushing was successful
false If the frame was not pushed, i.e., the queue was full; or the pipeline is halting

The documentation for this class was generated from the following file: