Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
hh::tool::Pool< T > Class Template Reference

Pool of data used by the memory manager. More...

#include "pool.h"

Inheritance diagram for hh::tool::Pool< T >:
Inheritance graph
Collaboration diagram for hh::tool::Pool< T >:
Collaboration graph

Public Member Functions

 Pool (size_t const &capacity)
 Create a pool with a certain capacity.
 
std::deque< std::shared_ptr< T > >::iterator begin ()
 Getter to the iterator to the beginning of the Pool.
 
std::deque< std::shared_ptr< T > >::iterator end ()
 Getter to the iterator to the end of the Pool.
 
size_t size ()
 Getter to the pool's size.
 
bool empty ()
 Returns true if the Pool is empty. (Thus begin() would equal end()).
 
size_t capacity () const
 Getter to the pool's capacity.
 
void push_back (std::shared_ptr< T > const &data)
 The function creates an element at the end of the pool and assigns the given data to it. Once inserted one waiting thread is woken up.
 
std::shared_ptr< T > pop_front ()
 Extract an element from the queue. If none is available wait until one become available.
 

Private Attributes

size_t const capacity_ = 1
 Capacity of the pool.
 
std::deque< std::shared_ptr< T > > queue_ = {}
 Actual storage used by the pool.
 
std::mutex mutex_ = {}
 Mutex used to protect the queue.
 
std::unique_ptr< std::condition_variable > conditionVariable_ = std::make_unique<std::condition_variable>()
 Condition variable to wake up a thread waiting for data.
 

Detailed Description

template<class T>
class hh::tool::Pool< T >

Pool of data used by the memory manager.

Template Parameters
TType stored in the pool

Definition at line 39 of file pool.h.

Constructor & Destructor Documentation

◆ Pool()

template<class T >
hh::tool::Pool< T >::Pool ( size_t const &  capacity)
inlineexplicit

Create a pool with a certain capacity.

Parameters
capacityPool's capacity

Definition at line 50 of file pool.h.

Member Function Documentation

◆ begin()

template<class T >
std::deque< std::shared_ptr< T > >::iterator hh::tool::Pool< T >::begin ( )
inline

Getter to the iterator to the beginning of the Pool.

Returns
Iterator to the beginning of the Pool

Definition at line 56 of file pool.h.

◆ capacity()

template<class T >
size_t hh::tool::Pool< T >::capacity ( ) const
inline

Getter to the pool's capacity.

Returns
Pool capacity

Definition at line 82 of file pool.h.

◆ empty()

template<class T >
bool hh::tool::Pool< T >::empty ( )
inline

Returns true if the Pool is empty. (Thus begin() would equal end()).

Returns
Returns true if the Pool is empty. (Thus begin() would equal end()).

Definition at line 73 of file pool.h.

◆ end()

template<class T >
std::deque< std::shared_ptr< T > >::iterator hh::tool::Pool< T >::end ( )
inline

Getter to the iterator to the end of the Pool.

Returns
Iterator to the end of the Pool

Definition at line 60 of file pool.h.

◆ pop_front()

template<class T >
std::shared_ptr< T > hh::tool::Pool< T >::pop_front ( )
inline

Extract an element from the queue. If none is available wait until one become available.

Returns
Element from the queue

Definition at line 104 of file pool.h.

◆ push_back()

template<class T >
void hh::tool::Pool< T >::push_back ( std::shared_ptr< T > const &  data)
inline

The function creates an element at the end of the pool and assigns the given data to it. Once inserted one waiting thread is woken up.

Parameters
dataData to insert
Exceptions
std::runtime_errorif the queue is overflowing

Definition at line 88 of file pool.h.

◆ size()

template<class T >
size_t hh::tool::Pool< T >::size ( )
inline

Getter to the pool's size.

Returns
Pool size

Definition at line 64 of file pool.h.

Member Data Documentation

◆ capacity_

template<class T >
size_t const hh::tool::Pool< T >::capacity_ = 1
private

Capacity of the pool.

Definition at line 41 of file pool.h.

◆ conditionVariable_

template<class T >
std::unique_ptr<std::condition_variable> hh::tool::Pool< T >::conditionVariable_ = std::make_unique<std::condition_variable>()
private

Condition variable to wake up a thread waiting for data.

Definition at line 45 of file pool.h.

◆ mutex_

template<class T >
std::mutex hh::tool::Pool< T >::mutex_ = {}
private

Mutex used to protect the queue.

Definition at line 43 of file pool.h.

◆ queue_

template<class T >
std::deque<std::shared_ptr<T> > hh::tool::Pool< T >::queue_ = {}
private

Actual storage used by the pool.

Definition at line 42 of file pool.h.