2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: Dynamic SQL runtime support
|
2003-10-05 08:33:56 +02:00
|
|
|
* MODULE: all.cpp
|
2001-05-23 15:26:42 +02:00
|
|
|
* DESCRIPTION: Internal 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): ______________________________________.
|
2001-11-02 21:40:15 +01:00
|
|
|
* 02 Nov 2001: Mike Nordell - Synch with FB1 changes.
|
2001-05-23 15:26:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
V4 Multi-threading changes.
|
|
|
|
|
|
|
|
-- direct calls to gds__ () & isc_ () entry points
|
|
|
|
|
|
|
|
THREAD_EXIT;
|
|
|
|
gds__ () or isc_ () call.
|
|
|
|
THREAD_ENTER;
|
|
|
|
|
|
|
|
-- calls through embedded GDML.
|
|
|
|
|
|
|
|
the following protocol will be used. Care should be taken if
|
|
|
|
nested FOR loops are added.
|
|
|
|
|
|
|
|
THREAD_EXIT; // last statment before FOR loop
|
|
|
|
|
|
|
|
FOR ...............
|
|
|
|
|
|
|
|
THREAD_ENTER; // First statment in FOR loop
|
|
|
|
.....some C code....
|
|
|
|
.....some C code....
|
|
|
|
THREAD_EXIT; // last statment in FOR loop
|
|
|
|
|
|
|
|
END_FOR;
|
|
|
|
|
|
|
|
THREAD_ENTER; // First statment after FOR loop
|
|
|
|
***************************************************************/
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
#include "../dsql/all.h"
|
2001-07-30 01:43:24 +02:00
|
|
|
#include "firebird.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include "../jrd/ib_stdio.h"
|
|
|
|
#include "../dsql/dsql.h"
|
2001-07-30 01:43:24 +02:00
|
|
|
#include "gen/codes.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
#include "../dsql/alld_proto.h"
|
|
|
|
#include "../dsql/errd_proto.h"
|
|
|
|
#include "../jrd/gds_proto.h"
|
|
|
|
#include "../jrd/thd_proto.h"
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
#include "../include/fb_vector.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
DsqlMemoryPool *DSQL_permanent_pool = 0;
|
|
|
|
typedef Firebird::vector<DsqlMemoryPool*> pool_vec_t;
|
|
|
|
static bool init_flag = false;
|
|
|
|
static Firebird::vector<DsqlMemoryPool*> *pools = 0;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
// Microsoft MSVC bug workaround
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define for if(0) {} else for
|
2001-05-23 15:26:42 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
void ALLD_fini()
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
if (!init_flag) {
|
2003-10-03 04:00:40 +02:00
|
|
|
ERRD_bugcheck("ALLD_fini - finishing before starting");
|
2001-11-02 21:40:15 +01:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
for (pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr)
|
2001-11-02 21:40:15 +01:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
if (*curr) {
|
2003-01-16 18:47:10 +01:00
|
|
|
DsqlMemoryPool::deletePool(*curr);
|
2001-11-02 21:40:15 +01:00
|
|
|
}
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
delete pools;
|
|
|
|
pools = 0;
|
2003-01-16 18:47:10 +01:00
|
|
|
DsqlMemoryPool::deletePool(DSQL_permanent_pool);
|
2001-12-24 03:51:06 +01:00
|
|
|
DSQL_permanent_pool = 0;
|
|
|
|
init_flag = false;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
void ALLD_init()
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
TSQL tdsql = GET_THREAD_DATA;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-11-02 21:40:15 +01:00
|
|
|
if (!init_flag)
|
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
init_flag = true;
|
2003-01-16 18:47:10 +01:00
|
|
|
DSQL_permanent_pool = DsqlMemoryPool::createPool();
|
2002-09-25 19:12:16 +02:00
|
|
|
pools = FB_NEW(*DSQL_permanent_pool) Firebird::vector<DsqlMemoryPool*>
|
2001-12-24 03:51:06 +01:00
|
|
|
(10, *DSQL_permanent_pool, dsql_type_vec);
|
|
|
|
tdsql->tsql_default = DSQL_permanent_pool;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-10 14:28:35 +01:00
|
|
|
void DsqlMemoryPool::ALLD_push(BLK object, DLLS * stack)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2001-05-24 16:54:26 +02:00
|
|
|
TSQL tdsql = GET_THREAD_DATA;
|
2001-12-24 03:51:06 +01:00
|
|
|
DsqlMemoryPool* pool = tdsql->tsql_default;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
DLLS node = pool->lls_cache.newBlock();
|
2001-05-23 15:26:42 +02:00
|
|
|
node->lls_object = object;
|
|
|
|
node->lls_next = *stack;
|
|
|
|
*stack = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-10 14:28:35 +01:00
|
|
|
BLK DsqlMemoryPool::ALLD_pop(DLLS *stack)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
DLLS node = *stack;
|
2001-05-23 15:26:42 +02:00
|
|
|
*stack = node->lls_next;
|
2001-12-24 03:51:06 +01:00
|
|
|
BLK object = node->lls_object;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
DsqlMemoryPool* pool = (DsqlMemoryPool*)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
|
|
|
}
|
|
|
|
|
2003-01-16 18:47:10 +01:00
|
|
|
DsqlMemoryPool* DsqlMemoryPool::createPool()
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-01-16 18:47:10 +01:00
|
|
|
DsqlMemoryPool *result = (DsqlMemoryPool *)internal_create(sizeof(DsqlMemoryPool));
|
|
|
|
new (&result->lls_cache) BlockCache<class dsql_lls> (*result);
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
if (!DSQL_permanent_pool)
|
2003-01-16 18:47:10 +01:00
|
|
|
return result;
|
2001-12-24 03:51:06 +01:00
|
|
|
|
|
|
|
for(pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr)
|
2001-05-24 16:54:26 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
if (!*curr)
|
2001-05-24 16:54:26 +02:00
|
|
|
{
|
2003-01-16 18:47:10 +01:00
|
|
|
*curr = result;
|
|
|
|
return result;
|
2001-05-24 16:54:26 +02:00
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
pools->resize(pools->size() + 10);
|
|
|
|
for(pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr)
|
2001-05-24 16:54:26 +02:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
if (!*curr)
|
2001-11-02 21:40:15 +01:00
|
|
|
{
|
2003-01-16 18:47:10 +01:00
|
|
|
*curr = result;
|
|
|
|
return result;
|
2001-11-02 21:40:15 +01:00
|
|
|
}
|
|
|
|
}
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-10-03 04:00:40 +02:00
|
|
|
ERRD_bugcheck("ALLD_fini - finishing before starting");
|
2003-01-16 18:47:10 +01:00
|
|
|
return NULL; //silencer
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
|
2003-01-16 18:47:10 +01:00
|
|
|
void DsqlMemoryPool::deletePool(DsqlMemoryPool *pool)
|
2001-05-23 15:26:42 +02:00
|
|
|
{
|
2003-01-16 18:47:10 +01:00
|
|
|
pool->lls_cache.~BlockCache<class dsql_lls>();
|
|
|
|
MemoryPool::deletePool(pool);
|
|
|
|
|
|
|
|
if (pool == DSQL_permanent_pool)
|
2001-12-24 03:51:06 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
for(pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr)
|
2001-11-02 21:40:15 +01:00
|
|
|
{
|
2003-01-16 18:47:10 +01:00
|
|
|
if (*curr == pool)
|
2001-11-02 21:40:15 +01:00
|
|
|
{
|
2001-12-24 03:51:06 +01:00
|
|
|
*curr = 0;
|
|
|
|
return;
|
2001-05-23 15:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|