The Pedigree Project  0.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MemoryPool Class Reference

#include <MemoryPool.h>

+ Collaboration diagram for MemoryPool:

Public Member Functions

 MemoryPool (const char *poolName)
 
bool initialise (size_t poolSize, size_t bufferSize=1024)
 
bool initialised ()
 Call if you aren't certain that the object has been initialised yet.
 
uintptr_t allocate ()
 
uintptr_t allocateNow ()
 
void free (uintptr_t buffer)
 Frees an allocated buffer, allowing it to be used elsewhere.
 
bool trim ()
 Trims the pool, freeing pages that are not otherwise in use.
 

Private Member Functions

uintptr_t allocateDoer (bool canBlock)
 Allocation doer. More...
 

Private Attributes

ConditionVariable m_Condition
 
Mutex m_Lock
 
size_t m_BufferSize
 Size of each buffer in this pool.
 
size_t m_BufferCount
 Number of buffers we have available.
 
MemoryRegion m_Pool
 MemoryRegion describing the actual pool of memory.
 
bool m_bInitialised
 Has this instance been initialised yet?
 
ExtensibleBitmap m_AllocBitmap
 Allocation bitmap.
 
MemoryPoolPressureHandler m_PressureHandler
 Memory pressure handler for this pool.
 

Detailed Description

MemoryPool - a class which encapsulates a pool of memory with constant sized buffers that can be allocated around the kernel. Intended to be used instead of the heap for areas where similar sized buffers are regularly allocated, such as networking code.

Definition at line 59 of file MemoryPool.h.

Member Function Documentation

uintptr_t MemoryPool::allocate ( )

Allocates a buffer from the pool. Will block if no buffers are available yet.

Definition at line 176 of file MemoryPool.cc.

Referenced by Dm9601::send(), and Ne2k::send().

+ Here is the caller graph for this function:

uintptr_t MemoryPool::allocateDoer ( bool  canBlock)
private

Allocation doer.

Todo:
better error handling

Definition at line 192 of file MemoryPool.cc.

References assert.

uintptr_t MemoryPool::allocateNow ( )

Allocates a buffer from the pool. If no buffers are available, this function will return straight away.

Returns
Zero if a buffer couldn't be allocated.

Definition at line 184 of file MemoryPool.cc.

Referenced by NetworkStack::deRegisterDevice().

+ Here is the caller graph for this function:

bool MemoryPool::initialise ( size_t  poolSize,
size_t  bufferSize = 1024 
)

Initialises the pool, preparing it for use

Parameters
poolSizeNumber of pages in the pool.
bufferSizeSize of each buffer. Will be rounded to the next power of two.

Definition at line 128 of file MemoryPool.cc.

References PhysicalMemoryManager::allocateRegion(), Dec, PhysicalMemoryManager::getPageSize(), Hex, PhysicalMemoryManager::instance(), VirtualAddressSpace::KernelMode, NOTICE, MemoryPressureManager::registerHandler(), PhysicalMemoryManager::virtualOnly, and VirtualAddressSpace::Write.


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