JeVois  1.16
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
jevois::BoundedBuffer< T, WhenFull, WhenEmpty > Class Template Reference

#include <jevois/Types/BoundedBuffer.H>

template<typename T, BlockingBehavior WhenFull, BlockingBehavior WhenEmpty>
class jevois::BoundedBuffer< T, WhenFull, WhenEmpty >

Thread-safe synchronized producer/consumer queue.

BoundedBuffer is designed for use in producer/consumer scenarios where multiple threads wish to push and pop data onto/from the buffer asynchronously. Threads that try to pop data when the buffer is empty will either sleep until data is actually available or get an exception (depending on template args), and threads that try to push data when the buffer is full will either block until some space is available in the buffer or get an exception (depending on template args).

Template Parameters
WhenFullblocking behavior (as jevois::BlockingBehavior) when attempting to push into a full buffer
WhenEmptyblocking behavior (as jevois::BlockingBehavior) when attempting to pop from an empty buffer

Definition at line 37 of file BoundedBuffer.H.

Inheritance diagram for jevois::BoundedBuffer< T, WhenFull, WhenEmpty >:

Public Member Functions

 BoundedBuffer (size_t const siz)
 Create a new BoundedBuffer with no data and a given size. More...
 
void push (T const &val)
 Push a new data element into the buffer, potentially sleeping or throwing if buffer is full, copy version. More...
 
void push (T &&val)
 Push a new data element into the buffer, potentially sleeping or throwing if buffer is full, move version. More...
 
pop ()
 Pop oldest data element off of the buffer, potentially sleeping until one is available or throwing if empty. More...
 
size_t filled_size () const
 Current number of items actually in the buffer. More...
 
size_t size () const
 Max (allocated at construction) size of the buffer. More...
 
void clear ()
 Clear all contents, resetting filled_size() to zero (size() remains unchanged at the max possible size) More...
 

Constructor & Destructor Documentation

◆ BoundedBuffer()

template<typename T , BlockingBehavior WhenFull, BlockingBehavior WhenEmpty>
jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::BoundedBuffer ( size_t const  siz)

Create a new BoundedBuffer with no data and a given size.

Member Function Documentation

◆ clear()

template<typename T , BlockingBehavior WhenFull, BlockingBehavior WhenEmpty>
void jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::clear ( )

Clear all contents, resetting filled_size() to zero (size() remains unchanged at the max possible size)

◆ filled_size()

template<typename T , BlockingBehavior WhenFull, BlockingBehavior WhenEmpty>
size_t jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::filled_size ( ) const

Current number of items actually in the buffer.

This function is mostly provided for informational messages and beware that the actual filled size may change in a multithreaded environment between the time we return here and the time the caller tries to use the result.

◆ pop()

template<typename T , BlockingBehavior WhenFull, BlockingBehavior WhenEmpty>
T jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::pop ( )

Pop oldest data element off of the buffer, potentially sleeping until one is available or throwing if empty.

◆ push() [1/2]

template<typename T , BlockingBehavior WhenFull, BlockingBehavior WhenEmpty>
void jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::push ( T &&  val)

Push a new data element into the buffer, potentially sleeping or throwing if buffer is full, move version.

◆ push() [2/2]

template<typename T , BlockingBehavior WhenFull, BlockingBehavior WhenEmpty>
void jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::push ( T const &  val)

Push a new data element into the buffer, potentially sleeping or throwing if buffer is full, copy version.

◆ size()

template<typename T , BlockingBehavior WhenFull, BlockingBehavior WhenEmpty>
size_t jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::size ( ) const

Max (allocated at construction) size of the buffer.


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