Tervel  1.0.0
A collection of wait-free containers and algorithms.
Classes | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
tervel::util::memory::rc::PoolManager Class Reference

A manager class for the reference count protected memory pools. More...

#include <pool_manager.h>

Classes

struct  ManagedPool
 

Public Member Functions

 PoolManager (size_t number_pools)
 PoolManager constructor. More...
 
 ~PoolManager ()
 
DescriptorPoolallocate_pool (const uint64_t tid)
 Allocates a pool for thread-local use. More...
 
void get_safe_elements (PoolElement **pool, uint64_t *count, uint64_t min_elem)
 This fuinction attempts to get 'count' many elements from the global pool. More...
 
void add_safe_elements (uint64_t pid, PoolElement *pool, PoolElement *pool_end=nullptr)
 Places excess elements into the global pool. More...
 
void add_unsafe_elements (uint64_t pid, PoolElement *pool)
 Places unsafe elements into the global pool. More...
 

Public Attributes

const size_t number_pools_
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (PoolManager)
 

Private Attributes

std::unique_ptr< ManagedPool[]> pools_
 

Friends

class DescriptorPool
 

Detailed Description

A manager class for the reference count protected memory pools.

Encapsulates a shared central pool between several thread-local pools. Idea is that each thread gets a local pool to grab descriptors from, and that each of these pools is managed by a single instance of this class. The thread local pools can periodically release their unused elements into the shared pool in this manager, or can take elements from the shared pools in this manager.

Constructor & Destructor Documentation

tervel::util::memory::rc::PoolManager::PoolManager ( size_t  number_pools)
inlineexplicit

PoolManager constructor.

RC PoolManager constructor

Parameters
number_poolsthis should be the number of Tervel threads
tervel::util::memory::rc::PoolManager::~PoolManager ( )

Member Function Documentation

void tervel::util::memory::rc::PoolManager::add_safe_elements ( uint64_t  pid,
PoolElement pool,
PoolElement pool_end = nullptr 
)

Places excess elements into the global pool.

Places excess elements into the global pool by performing an exchange on the current value of at position 'pid' then combing it was the excess elements and then storing the new value.

Parameters
pidthe position to add the elements
poolthe elements to end
pool_enda shortcut to the end of the pool list
void tervel::util::memory::rc::PoolManager::add_unsafe_elements ( uint64_t  pid,
PoolElement pool 
)

Places unsafe elements into the global pool.

Places unsafe elements into the global pool at position 'pid'. This function is only called from the DescriptorPool destructor.

Parameters
pidthe position to add the elements
poolthe elements to end
DescriptorPool* tervel::util::memory::rc::PoolManager::allocate_pool ( const uint64_t  tid)

Allocates a pool for thread-local use.

Allocates a pool and returns it to the calling thread

It creates a DescriptorPool object and returns the a pointer to that object

Parameters
tidTervel thread id for the calling thread
Returns
a DescriptorPool pointer
tervel::util::memory::rc::PoolManager::DISALLOW_COPY_AND_ASSIGN ( PoolManager  )
private
void tervel::util::memory::rc::PoolManager::get_safe_elements ( PoolElement **  pool,
uint64_t *  count,
uint64_t  min_elem 
)

This fuinction attempts to get 'count' many elements from the global pool.

A thread calling this function attempts to take any free elements and if successful will update the pool list, and count. It will keep trying until count >= min_elem or there are no more elements that can be taken from the global pool.

Parameters
poolA link list to pre-pend any elements taken from the global pool
countA count of the number of elements in pool
min_elemThe min desired value of count

Friends And Related Function Documentation

friend class DescriptorPool
friend

Member Data Documentation

const size_t tervel::util::memory::rc::PoolManager::number_pools_
std::unique_ptr<ManagedPool[]> tervel::util::memory::rc::PoolManager::pools_
private

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