IceFlow NDN-based stream processing library written in C++
Loading...
Searching...
No Matches
Public Member Functions | List of all members
iceflow::RingBuffer< T > Class Template Reference

This class provides a thread safe implementation of a queue. It uses boost::circular_buffer<T> as an internal queue data structure. Along with that it makes use of the C++ standard threading library to protect the queue and provide synchronization among multiple threads. More...

#include <ringbuffer.hpp>

Public Member Functions

 RingBuffer ()
 Constructor of the RingBuffer class.
 
RingBufferoperator= (const RingBuffer &)=delete
 Copy assignment.
 
 RingBuffer (RingBuffer const &other)
 Copy constructor of the RingBuffer class. This enables an instance of this class to be passed around as value.
 
int size () const
 
void push (const T &value)
 Pushes a value to the queue.
 
void pushData (T &value, int threshold)
 
bool empty () const
 Checks if the queue is empty.
 
bool tryAndPop (T &value)
 Tries to pop a value from the queue and copy it to the value passed in as an argument. This is a non blocking call and returns immediately with a status of retrieval.
 
std::shared_ptr< T > tryAndPop ()
 Tries to pop an item from the queue and returns a std::shared_ptr<T> This is a non blocking call and returns immediately with a status of retrieval.
 
void waitAndPop (T &value)
 Waits and pops an item from the queue and copies it to value passed in as an argument This is a blocking call and it waits until an item is available to be popped.
 
std::shared_ptr< T > waitAndPop ()
 Waits and pops an item from the queue and returns a shared_ptr<T> This is a blocking call and it waits until an item is available to be popped.
 
waitAndPopValue ()
 Waits and pops an item from the queue and returns a copy of the item This is a blocking call and it waits until an item is available to be popped.
 
bool waitForAndPop (T &value, std::chrono::milliseconds waitDuration)
 Waits and pops an item from the queue and copies it to value passed in as an argument. This is a blocking call with a timeout functionality.
 
std::shared_ptr< T > waitForAndPop (std::chrono::milliseconds waitDuration)
 Waits and pops an item from the queue and returns a std::shared_ptr<T>. This is a blocking call with a timeout functionality.
 

Detailed Description

template<typename T>
class iceflow::RingBuffer< T >

This class provides a thread safe implementation of a queue. It uses boost::circular_buffer<T> as an internal queue data structure. Along with that it makes use of the C++ standard threading library to protect the queue and provide synchronization among multiple threads.

Constructor & Destructor Documentation

◆ RingBuffer()

template<typename T >
iceflow::RingBuffer< T >::RingBuffer ( RingBuffer< T > const & other)
inline

Copy constructor of the RingBuffer class. This enables an instance of this class to be passed around as value.

Parameters
otherThe instance to be copied from

Member Function Documentation

◆ empty()

template<typename T >
bool iceflow::RingBuffer< T >::empty ( ) const
inline

Checks if the queue is empty.

Returns
true if the queue is empty, else false

◆ push()

template<typename T >
void iceflow::RingBuffer< T >::push ( const T & value)
inline

Pushes a value to the queue.

Parameters
valueThe item to be pushed to the queue

◆ tryAndPop() [1/2]

template<typename T >
std::shared_ptr< T > iceflow::RingBuffer< T >::tryAndPop ( )
inline

Tries to pop an item from the queue and returns a std::shared_ptr<T> This is a non blocking call and returns immediately with a status of retrieval.

Returns
nullptr if there is no item to be popped, else returns a shared_ptr pointing to the popped item.

◆ tryAndPop() [2/2]

template<typename T >
bool iceflow::RingBuffer< T >::tryAndPop ( T & value)
inline

Tries to pop a value from the queue and copy it to the value passed in as an argument. This is a non blocking call and returns immediately with a status of retrieval.

Parameters
valueAn instance to which the popped item is to be copied to.
Returns
true if there exists an item to be popped, else false.

◆ waitAndPop() [1/2]

template<typename T >
std::shared_ptr< T > iceflow::RingBuffer< T >::waitAndPop ( )
inline

Waits and pops an item from the queue and returns a shared_ptr<T> This is a blocking call and it waits until an item is available to be popped.

Returns
returns a std::shared_ptr<T> pointing to an instance of the popped item

◆ waitAndPop() [2/2]

template<typename T >
void iceflow::RingBuffer< T >::waitAndPop ( T & value)
inline

Waits and pops an item from the queue and copies it to value passed in as an argument This is a blocking call and it waits until an item is available to be popped.

Parameters
valueAn instance to which the popped item is to be copied to.

◆ waitAndPopValue()

template<typename T >
T iceflow::RingBuffer< T >::waitAndPopValue ( )
inline

Waits and pops an item from the queue and returns a copy of the item This is a blocking call and it waits until an item is available to be popped.

Returns
returns a copy of the instance of the popped item.

◆ waitForAndPop() [1/2]

template<typename T >
std::shared_ptr< T > iceflow::RingBuffer< T >::waitForAndPop ( std::chrono::milliseconds waitDuration)
inline

Waits and pops an item from the queue and returns a std::shared_ptr<T>. This is a blocking call with a timeout functionality.

Parameters
waitDurationWait for at most waitDuration
Returns
returns nullptr if it timed out, else returns a std::shared_ptr<T> pointing to an instance of item popped.

◆ waitForAndPop() [2/2]

template<typename T >
bool iceflow::RingBuffer< T >::waitForAndPop ( T & value,
std::chrono::milliseconds waitDuration )
inline

Waits and pops an item from the queue and copies it to value passed in as an argument. This is a blocking call with a timeout functionality.

Parameters
valueAn instance to which the popped item is to be copied to.
waitDurationWait for at most waitDuration.
Returns
returns false if the wait timedout, returns true if an item was popped and copied.

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