21#ifndef HEDGEHOG_POOL_H_ 
   22#define HEDGEHOG_POOL_H_ 
   29#include <condition_variable> 
   42  std::deque<std::shared_ptr<T>> 
queue_ = {}; 
 
   44  std::unique_ptr<std::condition_variable>
 
   56  typename std::deque<std::shared_ptr<T>>::iterator 
begin() { 
return this->queue_.begin(); }
 
   60  typename std::deque<std::shared_ptr<T>>::iterator 
end() { 
return this->queue_.end(); }
 
   90    this->queue_.push_back(data);
 
   93      std::ostringstream oss;
 
   94      oss << 
"The queue is overflowing, the same data " << data
 
   95          << 
" has been returned to the memory manager too many times: " << __FUNCTION__;
 
   96      throw (std::runtime_error(oss.str()));
 
  105    std::unique_lock<std::mutex> lock(
mutex_);
 
  106    std::shared_ptr<T> ret = 
nullptr;
 
Pool of data used by the memory manager.
std::deque< std::shared_ptr< T > >::iterator end()
Getter to the iterator to the end of the Pool.
std::unique_ptr< std::condition_variable > conditionVariable_
Condition variable to wake up a thread waiting for data.
std::shared_ptr< T > pop_front()
Extract an element from the queue. If none is available wait until one become available.
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.
size_t size()
Getter to the pool's size.
size_t capacity() const
Getter to the pool's capacity.
bool empty()
Returns true if the Pool is empty. (Thus begin() would equal end()).
size_t const capacity_
Capacity of the pool.
std::mutex mutex_
Mutex used to protect the queue.
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....
std::deque< std::shared_ptr< T > > queue_
Actual storage used by the pool.