JeVois  1.0
JeVois Smart Embedded Machine Vision Toolkit
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

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

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

Definition at line 22 of file BoundedBufferImpl.H.

Member Function Documentation

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

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

Definition at line 80 of file BoundedBufferImpl.H.

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

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.

Definition at line 70 of file BoundedBufferImpl.H.

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

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

Definition at line 54 of file BoundedBufferImpl.H.

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

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

Definition at line 28 of file BoundedBufferImpl.H.

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

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

Definition at line 41 of file BoundedBufferImpl.H.

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

Max (allocated at construction) size of the buffer.

Definition at line 75 of file BoundedBufferImpl.H.


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