GLIM
Loading...
Searching...
No Matches
Public Member Functions | List of all members
glim::ConcurrentVector< T, Alloc > Class Template Reference

Simple thread-safe vector with mutex-lock. More...

#include <concurrent_vector.hpp>

Public Member Functions

 ConcurrentVector (const DataStorePolicy &policy=DataStorePolicy::UNLIMITED())
 
void submit_end_of_data ()
 
bool empty () const
 
int size () const
 
void reserve (int n)
 
void push_back (const T &value)
 
void clear ()
 
front () const
 
back () const
 
template<typename Container >
void insert (const Container &new_values)
 Insert new_values at the end of the container.
 
std::optional< T > pop ()
 Get the first element in the queue.
 
std::optional< T > pop_wait ()
 Get the first element in the queue. If the queue is empty, this method waits until a new data arrives or EOD is submitted.
 
std::vector< T, Alloc > get_all_and_clear_wait ()
 Get all the data and clear the container. If the queue is empty, this method waits until a new data arrives or EOD is submitted.
 
std::vector< T, Alloc > get_all_and_clear ()
 Get all the data and clear the container.
 
std::vector< T, Alloc > get_and_clear (int num_max)
 Get up to N data and erase them from the container.
 

Detailed Description

template<typename T, typename Alloc = std::allocator<T>>
class glim::ConcurrentVector< T, Alloc >

Simple thread-safe vector with mutex-lock.

Note
This class is performant in the single-thread-input single-thread-output situation. In the multi-thread-input multi-thread-output situation, consider using concurrent containers in TBB.
Template Parameters
TData type
AllocAllocator

Member Function Documentation

◆ get_all_and_clear()

template<typename T , typename Alloc = std::allocator<T>>
std::vector< T, Alloc > glim::ConcurrentVector< T, Alloc >::get_all_and_clear ( )
inline

Get all the data and clear the container.

Returns
std::vector<T, Alloc> All data

◆ get_all_and_clear_wait()

template<typename T , typename Alloc = std::allocator<T>>
std::vector< T, Alloc > glim::ConcurrentVector< T, Alloc >::get_all_and_clear_wait ( )
inline

Get all the data and clear the container. If the queue is empty, this method waits until a new data arrives or EOD is submitted.

Returns
std::vector<T, Alloc> All data or empty if EOD is submitted.

◆ get_and_clear()

template<typename T , typename Alloc = std::allocator<T>>
std::vector< T, Alloc > glim::ConcurrentVector< T, Alloc >::get_and_clear ( int  num_max)
inline

Get up to N data and erase them from the container.

Parameters
num_maxMaximum number of data
Returns
std::vector<T, Alloc> Up to num_max data

◆ insert()

template<typename T , typename Alloc = std::allocator<T>>
template<typename Container >
void glim::ConcurrentVector< T, Alloc >::insert ( const Container &  new_values)
inline

Insert new_values at the end of the container.

Parameters
new_valuesValues to be inserted

◆ pop()

template<typename T , typename Alloc = std::allocator<T>>
std::optional< T > glim::ConcurrentVector< T, Alloc >::pop ( )
inline

Get the first element in the queue.

Returns
nullopt if the queue is empty

◆ pop_wait()

template<typename T , typename Alloc = std::allocator<T>>
std::optional< T > glim::ConcurrentVector< T, Alloc >::pop_wait ( )
inline

Get the first element in the queue. If the queue is empty, this method waits until a new data arrives or EOD is submitted.

Returns
nullopt if the queue is empty and EOD is submitted.

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