8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 07:23:03 +01:00
This commit is contained in:
dimitr 2008-02-20 15:25:20 +00:00
parent 32acb864fb
commit e3e9d3c172
2 changed files with 53 additions and 58 deletions

View File

@ -246,8 +246,8 @@ MemoryPool* MemoryPool::getContextPool()
} }
// Default stats group and default pool // Default stats group and default pool
MemoryStats* MemoryPool::default_stats_group = 0; MemoryStats* MemoryPool::default_stats_group = NULL;
MemoryPool* MemoryPool::processMemoryPool = 0; MemoryPool* MemoryPool::processMemoryPool = NULL;
// Initialize process memory pool (called from InstanceControl). // Initialize process memory pool (called from InstanceControl).
// At this point also set contextMemoryPool for main thread // At this point also set contextMemoryPool for main thread
@ -1072,7 +1072,7 @@ void MemoryPool::print_contents(FILE *file, bool used_only,
fprintf(file, "********* End of output for pool %p.\n", this); fprintf(file, "********* End of output for pool %p.\n", this);
} }
MemoryPool* MemoryPool::internal_create(size_t instance_size, MemoryPool* parent, MemoryStats &stats) MemoryPool* MemoryPool::createPool(MemoryPool* parent, MemoryStats &stats)
{ {
MemoryPool *pool; MemoryPool *pool;
#ifndef USE_VALGRIND #ifndef USE_VALGRIND
@ -1081,7 +1081,7 @@ MemoryPool* MemoryPool::internal_create(size_t instance_size, MemoryPool* parent
// difficult to make memory pass through any delayed free list in this case // difficult to make memory pass through any delayed free list in this case
if (parent) { if (parent) {
parent->lock.enter(); parent->lock.enter();
const size_t size = MEM_ALIGN(instance_size + sizeof(MemoryRedirectList)); const size_t size = MEM_ALIGN(sizeof(MemoryPool) + sizeof(MemoryRedirectList));
void* mem = parent->internal_alloc(size, TYPE_POOL); void* mem = parent->internal_alloc(size, TYPE_POOL);
if (!mem) { if (!mem) {
parent->lock.leave(); parent->lock.leave();
@ -1107,7 +1107,7 @@ MemoryPool* MemoryPool::internal_create(size_t instance_size, MemoryPool* parent
// This is the exact initial layout of memory pool in the first extent // // This is the exact initial layout of memory pool in the first extent //
// MemoryExtent // MemoryExtent
// MemoryBlock // MemoryBlock
// MemoryPool (instance_size) // MemoryPool
// MemoryBlock // MemoryBlock
// FreeBlocksTree::ItemList // FreeBlocksTree::ItemList
// MemoryBlock // MemoryBlock
@ -1130,7 +1130,7 @@ MemoryPool* MemoryPool::internal_create(size_t instance_size, MemoryPool* parent
MemoryPool(NULL, stats, mem, mem + MemoryPool(NULL, stats, mem, mem +
MEM_ALIGN(sizeof(MemoryExtent)) + MEM_ALIGN(sizeof(MemoryExtent)) +
MEM_ALIGN(sizeof(MemoryBlock)) + MEM_ALIGN(sizeof(MemoryBlock)) +
MEM_ALIGN(instance_size) + MEM_ALIGN(sizeof(MemoryPool)) +
MEM_ALIGN(sizeof(MemoryBlock))); MEM_ALIGN(sizeof(MemoryBlock)));
pool->increment_mapping(EXTENT_SIZE); pool->increment_mapping(EXTENT_SIZE);
@ -1139,13 +1139,13 @@ MemoryPool* MemoryPool::internal_create(size_t instance_size, MemoryPool* parent
poolBlk->mbk_pool = pool; poolBlk->mbk_pool = pool;
poolBlk->mbk_flags = MBK_USED; poolBlk->mbk_flags = MBK_USED;
poolBlk->mbk_type = TYPE_POOL; poolBlk->mbk_type = TYPE_POOL;
poolBlk->mbk_small.mbk_length = MEM_ALIGN(instance_size); poolBlk->mbk_small.mbk_length = MEM_ALIGN(sizeof(MemoryPool));
poolBlk->mbk_small.mbk_prev_length = 0; poolBlk->mbk_small.mbk_prev_length = 0;
MemoryBlock* hdr = (MemoryBlock*) (mem + MemoryBlock* hdr = (MemoryBlock*) (mem +
MEM_ALIGN(sizeof(MemoryExtent)) + MEM_ALIGN(sizeof(MemoryExtent)) +
MEM_ALIGN(sizeof(MemoryBlock)) + MEM_ALIGN(sizeof(MemoryBlock)) +
MEM_ALIGN(instance_size)); MEM_ALIGN(sizeof(MemoryPool)));
hdr->mbk_pool = pool; hdr->mbk_pool = pool;
hdr->mbk_flags = MBK_USED; hdr->mbk_flags = MBK_USED;
hdr->mbk_type = TYPE_LEAFPAGE; hdr->mbk_type = TYPE_LEAFPAGE;
@ -1154,13 +1154,13 @@ MemoryPool* MemoryPool::internal_create(size_t instance_size, MemoryPool* parent
MemoryBlock* blk = (MemoryBlock *)(mem + MemoryBlock* blk = (MemoryBlock *)(mem +
MEM_ALIGN(sizeof(MemoryExtent)) + MEM_ALIGN(sizeof(MemoryExtent)) +
MEM_ALIGN(sizeof(MemoryBlock)) + MEM_ALIGN(sizeof(MemoryBlock)) +
MEM_ALIGN(instance_size) + MEM_ALIGN(sizeof(MemoryPool)) +
MEM_ALIGN(sizeof(MemoryBlock)) + MEM_ALIGN(sizeof(MemoryBlock)) +
MEM_ALIGN(sizeof(FreeBlocksTree::ItemList))); MEM_ALIGN(sizeof(FreeBlocksTree::ItemList)));
int blockLength = EXTENT_SIZE - int blockLength = EXTENT_SIZE -
MEM_ALIGN(sizeof(MemoryExtent)) - MEM_ALIGN(sizeof(MemoryExtent)) -
MEM_ALIGN(sizeof(MemoryBlock)) - MEM_ALIGN(sizeof(MemoryBlock)) -
MEM_ALIGN(instance_size) - MEM_ALIGN(sizeof(MemoryPool)) -
MEM_ALIGN(sizeof(MemoryBlock)) - MEM_ALIGN(sizeof(MemoryBlock)) -
MEM_ALIGN(sizeof(FreeBlocksTree::ItemList)) - MEM_ALIGN(sizeof(FreeBlocksTree::ItemList)) -
MEM_ALIGN(sizeof(MemoryBlock)); MEM_ALIGN(sizeof(MemoryBlock));

View File

@ -294,10 +294,6 @@ protected:
~MemoryPool() { ~MemoryPool() {
} }
// Used to create MemoryPool descendants
static MemoryPool* internal_create(size_t instance_size,
MemoryPool* parent = NULL, MemoryStats& stats = *default_stats_group);
public: public:
// Default statistics group for process // Default statistics group for process
static MemoryStats* default_stats_group; static MemoryStats* default_stats_group;
@ -306,9 +302,8 @@ public:
static MemoryPool* processMemoryPool; static MemoryPool* processMemoryPool;
// Create memory pool instance // Create memory pool instance
static MemoryPool* createPool(MemoryPool* parent = NULL, MemoryStats& stats = *default_stats_group) { static MemoryPool* createPool(MemoryPool* parent = NULL,
return internal_create(sizeof(MemoryPool), parent, stats); MemoryStats& stats = *default_stats_group);
}
// Set context pool for current thread of execution // Set context pool for current thread of execution
static MemoryPool* setContextPool(MemoryPool* newPool); static MemoryPool* setContextPool(MemoryPool* newPool);