The Pedigree Project
0.1
|
#include <MemoryPool.h>
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. | |
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.
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().
|
private |
Allocation doer.
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.
Definition at line 184 of file MemoryPool.cc.
Referenced by NetworkStack::deRegisterDevice().
bool MemoryPool::initialise | ( | size_t | poolSize, |
size_t | bufferSize = 1024 |
||
) |
Initialises the pool, preparing it for use
poolSize | Number of pages in the pool. |
bufferSize | Size 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.