8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 23:23:04 +01:00
firebird-mirror/src/alice/all.cpp

201 lines
4.5 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
//____________________________________________________________
//
// PROGRAM: Alice (All Else) Utility
// MODULE: all.cpp
// DESCRIPTION: Block allocator
//
// The contents of this file are subject to the Interbase Public
// License Version 1.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy
// of the License at http://www.Inprise.com/IPL.html
//
// Software distributed under the License is distributed on an
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
// or implied. See the License for the specific language governing
// rights and limitations under the License.
//
// The Original Code was created by Inprise Corporation
// and its predecessors. Portions created by Inprise Corporation are
// Copyright (C) Inprise Corporation.
//
// All Rights Reserved.
// Contributor(s): ______________________________________.
//
//
//____________________________________________________________
//
// $Id: all.cpp,v 1.10 2003-02-12 12:42:41 brodsom Exp $
2001-05-23 15:26:42 +02:00
//
#include "../alice/all.h"
#include "firebird.h"
2001-12-24 03:51:06 +01:00
//#include "../jrd/ib_stdio.h"
//#include "../jrd/common.h"
//#include "../jrd/ibsetjmp.h"
#include "../alice/alice.h"
//#include "../alice/all.h"
//#include "../alice/alloc.h"
//#include "../alice/lls.h"
//#include "../alice/all_proto.h"
//#include "../jrd/gds_proto.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/thd_proto.h"
#include "../common/classes/alloc.h"
2001-05-23 15:26:42 +02:00
//____________________________________________________________
//
// Get rid of everything.
//
void ALLA_fini(void)
{
2001-12-24 03:51:06 +01:00
TGBL tdgbl = GET_THREAD_DATA;
2001-05-23 15:26:42 +02:00
2001-12-24 03:51:06 +01:00
for(tgbl::pool_vec_t::iterator curr = tdgbl->pools.begin();
curr != tdgbl->pools.end(); ++curr)
{
AliceMemoryPool::deletePool(*curr);
2001-12-24 03:51:06 +01:00
*curr = 0;
2001-05-23 15:26:42 +02:00
}
2001-12-24 03:51:06 +01:00
tdgbl->pools.clear();
2001-05-23 15:26:42 +02:00
2001-12-28 06:16:31 +01:00
tdgbl->ALICE_default_pool = 0;
tdgbl->ALICE_permanent_pool = 0;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
//
// Initialize the pool system.
//
void ALLA_init(void)
{
TGBL tdgbl;
tdgbl = GET_THREAD_DATA;
#ifdef NOT_USED_OR_REPLACED
2001-12-24 03:51:06 +01:00
tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool =
AliceMemoryPool::create_new_pool();
#else
2001-12-28 06:16:31 +01:00
// TMN: John, what pool to use here?
tdgbl->ALICE_permanent_pool = AliceMemoryPool::createPool();
2001-12-28 06:16:31 +01:00
tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool;
2001-12-24 03:51:06 +01:00
#endif
2001-05-23 15:26:42 +02:00
}
2001-12-24 03:51:06 +01:00
void AliceMemoryPool::ALLA_push(class blk *object, class lls** stack)
2001-05-23 15:26:42 +02:00
{
2001-12-24 03:51:06 +01:00
/**************************************
*
* A L L _ p u s h
*
**************************************
*
* Functional description
* Push an object on an LLS stack.
*
**************************************/
class lls* node;
AliceMemoryPool* pool;
TGBL tdgbl = GET_THREAD_DATA;
2001-05-23 15:26:42 +02:00
pool = tdgbl->ALICE_default_pool;
2001-12-24 03:51:06 +01:00
node = pool->lls_cache.newBlock();
2001-05-23 15:26:42 +02:00
node->lls_object = object;
node->lls_next = *stack;
*stack = node;
}
BLK AliceMemoryPool::ALLA_pop(LLS *stack)
2001-05-23 15:26:42 +02:00
{
2001-12-24 03:51:06 +01:00
/**************************************
*
* A L L _ p o p
*
**************************************
*
* Functional description
* Pop an object off a linked list stack. Save the node for
* further use.
*
**************************************/
LLS node;
2001-12-24 03:51:06 +01:00
AliceMemoryPool* pool;
BLK object;
2001-05-23 15:26:42 +02:00
node = *stack;
*stack = node->lls_next;
2001-12-24 03:51:06 +01:00
object = node->lls_object;
2001-05-23 15:26:42 +02:00
2001-12-24 03:51:06 +01:00
pool = (AliceMemoryPool*)MemoryPool::blk_pool(node);
pool->lls_cache.returnBlock(node);
2001-05-23 15:26:42 +02:00
2001-12-24 03:51:06 +01:00
return object;
2001-05-23 15:26:42 +02:00
}
#ifdef NOT_USED_OR_REPLACED
2001-12-24 03:51:06 +01:00
AliceMemoryPool* AliceMemoryPool::create_new_pool(MemoryPool* parent)
2001-05-23 15:26:42 +02:00
{
2001-12-24 03:51:06 +01:00
/**************************************
*
* A L L _ p o o l
*
**************************************
*
* Functional description
* Allocate a new pool.
*
**************************************/
TGBL tdgbl = GET_THREAD_DATA;
// TMN: John, is this correct?
AliceMemoryPool* pool = new(0, parent) AliceMemoryPool(parent);
tgbl::pool_vec_t::iterator curr;
for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr)
{
if (!*curr)
{
*curr = pool;
return pool;
}
2001-05-23 15:26:42 +02:00
}
2001-12-24 03:51:06 +01:00
tdgbl->pools.resize(tdgbl->pools.size() + 10);
for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr)
{
if (!*curr)
{
*curr = pool;
return pool;
}
2001-05-23 15:26:42 +02:00
}
2001-12-24 03:51:06 +01:00
//assert(0);
//BUGCHECK ("ALLA_fini - finishing before starting");
return 0;//pool; // Never reached, but makes the compiler happy.
2001-05-23 15:26:42 +02:00
}
2001-12-24 03:51:06 +01:00
#endif
2001-05-23 15:26:42 +02:00
void AliceMemoryPool::deletePool(AliceMemoryPool* pool) {
2001-12-24 03:51:06 +01:00
TGBL tdgbl = GET_THREAD_DATA;
tgbl::pool_vec_t::iterator curr;
for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr)
{
if (*curr == pool)
2001-12-24 03:51:06 +01:00
{
*curr = 0;
return;
}
2001-05-23 15:26:42 +02:00
}
pool->lls_cache.~BlockCache<lls>();
MemoryPool::deletePool(pool);
2001-05-23 15:26:42 +02:00
}