Tervel
1.0.0
A collection of wait-free containers and algorithms.
|
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 () | |
DescriptorPool * | allocate_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 |
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.
|
inlineexplicit |
PoolManager constructor.
RC PoolManager constructor
number_pools | this should be the number of Tervel threads |
tervel::util::memory::rc::PoolManager::~PoolManager | ( | ) |
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.
pid | the position to add the elements |
pool | the elements to end |
pool_end | a 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.
pid | the position to add the elements |
pool | the 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
tid | Tervel thread id for the calling thread |
|
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.
pool | A link list to pre-pend any elements taken from the global pool |
count | A count of the number of elements in pool |
min_elem | The min desired value of count |
|
friend |
const size_t tervel::util::memory::rc::PoolManager::number_pools_ |
|
private |