Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
LimitedPool Class Reference

Implementation of a Pool interface that takes memory from mainBufferPool (configurable) but limits the number of buffers allocatable. More...

#include <LimitedPool.hxx>

Inheritance diagram for LimitedPool:
Pool Atomic

Public Member Functions

 LimitedPool (unsigned entry_size, unsigned entry_count, Pool *base_pool=nullptr)
 
size_t free_items () override
 Number of free items in the pool.
 
size_t free_items (size_t size) override
 Number of free items in the pool for a given allocation size.
 
- Public Member Functions inherited from Pool
size_t total_size ()
 
template<class BufferType >
void alloc (Buffer< BufferType > **result, Executable *flow=NULL)
 Get a free item out of the pool.
 
template<class BufferType >
void alloc (BufferPtr< BufferType > *result)
 Get a free item out of the pool.
 
template<class BufferType >
void alloc_async (Executable *flow)
 Get a free item out of the pool.
 

Protected Member Functions

BufferBasealloc_untyped (size_t size, Executable *flow) override
 Internal helper funciton used by the Buffer implementation.
 
void free (BufferBase *item) override
 Function called when a buffer refcount reaches zero.
 
- Protected Member Functions inherited from Pool
 Pool ()
 Default Constructor.
 
virtual ~Pool ()
 default destructor.
 

Private Member Functions

Poolbase_pool ()
 
- Private Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Private Attributes

uint16_t itemSize_
 How many bytes each entry should be.
 
uint16_t freeCount_
 How many entries can still be allocated.
 
PoolbasePool_
 Where to allocate memory from.
 
Q waitingQueue_
 Async allocators waiting for free buffers.
 

Additional Inherited Members

- Static Public Member Functions inherited from Pool
template<class BufferType >
static void alloc_async_init (BufferBase *base, Buffer< BufferType > **result)
 Cast the result of an asynchronous allocation and perform a placement new on it.
 
- Protected Attributes inherited from Pool
size_t totalSize
 keep track of total allocated size of memory
 

Detailed Description

Implementation of a Pool interface that takes memory from mainBufferPool (configurable) but limits the number of buffers allocatable.

Later async allocations will be blocked until an earlier buffer gets freed. Freed buffers go back to the underlying pool, so no memory is captive in this object.

Definition at line 47 of file LimitedPool.hxx.

Constructor & Destructor Documentation

◆ LimitedPool()

LimitedPool::LimitedPool ( unsigned  entry_size,
unsigned  entry_count,
Pool base_pool = nullptr 
)
inline
Parameters
entry_sizeis the byte size of the objects to be allocated. Usually sizeof(Buffer<YourType>).
entry_countmax number of buffer that can be allocated via this pool.
base_poolwhere to allocate the memory for our objects. If nullptr, uses the mainBufferPool.

Definition at line 56 of file LimitedPool.hxx.

Member Function Documentation

◆ alloc_untyped()

BufferBase * LimitedPool::alloc_untyped ( size_t  size,
Executable flow 
)
inlineoverrideprotectedvirtual

Internal helper funciton used by the Buffer implementation.

Implements Pool.

Definition at line 80 of file LimitedPool.hxx.

◆ base_pool()

Pool * LimitedPool::base_pool ( )
inlineprivate
Returns
the pool from which we should get the actual memory we have.

Definition at line 135 of file LimitedPool.hxx.

◆ free()

void LimitedPool::free ( BufferBase item)
inlineoverrideprotectedvirtual

Function called when a buffer refcount reaches zero.

Implements Pool.

Definition at line 111 of file LimitedPool.hxx.

◆ free_items() [1/2]

size_t LimitedPool::free_items ( )
inlineoverridevirtual

Number of free items in the pool.

Implements Pool.

Definition at line 65 of file LimitedPool.hxx.

◆ free_items() [2/2]

size_t LimitedPool::free_items ( size_t  size)
inlineoverridevirtual

Number of free items in the pool for a given allocation size.

Parameters
sizesize of interest
Returns
number of free items in the pool for a given allocation size

Implements Pool.

Definition at line 73 of file LimitedPool.hxx.

Member Data Documentation

◆ basePool_

Pool* LimitedPool::basePool_
private

Where to allocate memory from.

Definition at line 149 of file LimitedPool.hxx.

◆ freeCount_

uint16_t LimitedPool::freeCount_
private

How many entries can still be allocated.

Definition at line 147 of file LimitedPool.hxx.

◆ itemSize_

uint16_t LimitedPool::itemSize_
private

How many bytes each entry should be.

Definition at line 145 of file LimitedPool.hxx.

◆ waitingQueue_

Q LimitedPool::waitingQueue_
private

Async allocators waiting for free buffers.

Definition at line 151 of file LimitedPool.hxx.


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