8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 19:23:03 +01:00

Fixed my bug in alice. Also some style changes and cleanup.

This commit is contained in:
alexpeshkoff 2004-09-01 14:51:33 +00:00
parent 4053524807
commit edf58bab73
6 changed files with 93 additions and 228 deletions

View File

@ -24,7 +24,7 @@
//
//____________________________________________________________
//
// $Id: alice.cpp,v 1.70 2004-08-30 18:10:28 alexpeshkoff Exp $
// $Id: alice.cpp,v 1.71 2004-09-01 14:51:33 alexpeshkoff Exp $
//
// 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE"
// conditionals, as the engine now fully supports
@ -193,19 +193,8 @@ int common_main(int argc,
fAnsiCP = (GetConsoleCP() == GetACP());
#endif
AliceGlobals* tdgbl = 0;
try
{
// FREE: during function exit in catch
tdgbl = FB_NEW(*getDefaultMemoryPool())
AliceGlobals(*getDefaultMemoryPool(), output_proc, output_data);
}
catch (std::bad_alloc)
{
// NOMEM: return error, FREE: during function exit in catch
return FINI_ERROR;
}
AliceGlobals gblInstance(output_proc, output_data);
AliceGlobals* tdgbl = &gblInstance;
AliceGlobals::putSpecific(tdgbl);
try {
@ -626,15 +615,14 @@ int common_main(int argc,
int exit_code = tdgbl->exit_code;
// Close the status output file
if (tdgbl->sw_redirect == REDIRECT && tdgbl->output_file != NULL) {
if (tdgbl->sw_redirect == REDIRECT && tdgbl->output_file != NULL)
{
fclose(tdgbl->output_file);
tdgbl->output_file = NULL;
}
AliceGlobals::restoreSpecific();
delete tdgbl;
#if defined(DEBUG_GDS_ALLOC) && !defined(SUPERSERVER)
gds_alloc_report(0, __FILE__, __LINE__);
#endif

View File

@ -162,16 +162,12 @@ private:
}
public:
AliceGlobals(MemoryPool& p, Jrd::pfn_svc_output outProc, Jrd::Service* outData)
: ThreadData(ThreadData::tddALICE), pools(p),
AliceGlobals(Jrd::pfn_svc_output outProc, Jrd::Service* outData)
: ThreadData(ThreadData::tddALICE),
output_proc(outProc), output_data(outData),
ALICE_permanent_pool(0), ALICE_default_pool(0)
ALICE_default_pool(0)
{
}
~AliceGlobals()
{
subsystemCleanup();
}
AliceMemoryPool* getDefaultPool()
{
@ -179,10 +175,7 @@ public:
}
user_action ALICE_data;
AliceMemoryPool* ALICE_permanent_pool;
ISC_STATUS_ARRAY status_vector;
typedef Firebird::HalfStaticArray<AliceMemoryPool*, 4> PoolsArray;
PoolsArray pools;
int exit_code;
Jrd::pfn_svc_output output_proc;
Jrd::Service* output_data;
@ -197,7 +190,9 @@ public:
#ifdef SUPERSERVER
static inline AliceGlobals* getSpecific() {
return (AliceGlobals*) ThreadData::getSpecific();
ThreadData* tData = ThreadData::getSpecific();
fb_assert (tData->getType() == ThreadData::tddALICE)
return (AliceGlobals*) tData;
}
static inline void putSpecific(AliceGlobals* tdgbl) {
tdgbl->ThreadData::putSpecific();
@ -215,20 +210,6 @@ public:
static inline void restoreSpecific() {
}
#endif
private:
// Perform AliceGlobals cleanup
void subsystemCleanup(void)
{
for (int i = 0; i < pools.getCount(); ++i)
{
AliceMemoryPool::deletePool(pools[i]);
pools[i] = 0;
}
pools.clear();
setDefaultPool(0);
ALICE_permanent_pool = 0;
}
};
typedef Firebird::SubsystemContextPoolHolder <AliceGlobals, AliceMemoryPool>

View File

@ -24,7 +24,7 @@
//
//____________________________________________________________
//
// $Id: all.cpp,v 1.28 2004-08-30 18:10:28 alexpeshkoff Exp $
// $Id: all.cpp,v 1.29 2004-09-01 14:51:33 alexpeshkoff Exp $
//
#include "firebird.h"
@ -34,114 +34,12 @@
#include "../jrd/thd.h"
#include "../common/classes/alloc.h"
#ifdef NOT_USED_OR_REPLACED
void AliceMemoryPool::ALLA_push(blk* object, alice_lls** stack)
{
/**************************************
*
* A L L _ p u s h
*
**************************************
*
* Functional description
* Push an object on an LLS stack.
*
**************************************/
AliceGlobals* tdgbl = AliceGlobals::getSpecific();
AliceMemoryPool* pool = tdgbl->ALICE_default_pool;
alice_lls* node = pool->lls_cache.newBlock();
node->lls_object = object;
node->lls_next = *stack;
*stack = node;
}
BLK AliceMemoryPool::ALLA_pop(alice_lls** stack)
{
/**************************************
*
* A L L _ p o p
*
**************************************
*
* Functional description
* Pop an object off a linked list stack. Save the node for
* further use.
*
**************************************/
alice_lls* node = *stack;
*stack = node->lls_next;
BLK object = node->lls_object;
AliceMemoryPool* pool = (AliceMemoryPool*)MemoryPool::blk _pool(node);
pool->lls_cache.returnBlock(node);
return object;
}
AliceMemoryPool* AliceMemoryPool::create_new_pool(MemoryPool* parent)
{
/**************************************
*
* A L L _ p o o l
*
**************************************
*
* Functional description
* Allocate a new pool.
*
**************************************/
AliceGlobals* tdgbl = AliceGlobals::getSpecific();
// TMN: John, is this correct?
AliceMemoryPool* pool = new(0, parent) AliceMemoryPool(parent);
AliceGlobals::pool_vec_t::iterator curr;
for (curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr)
{
if (!*curr)
{
*curr = pool;
return pool;
}
}
tdgbl->pools.resize(tdgbl->pools.size() + 10);
for (curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr)
{
if (!*curr)
{
*curr = pool;
return pool;
}
}
//fb_assert(0);
//BUGCHECK ("ALLA_fini - finishing before starting");
return 0;//pool; // Never reached, but makes the compiler happy.
}
#endif //NOT_USED_OR_REPLACED
AliceMemoryPool* AliceMemoryPool::createPool() {
AliceMemoryPool* result = (AliceMemoryPool*)internal_create(sizeof(AliceMemoryPool));
AliceGlobals::getSpecific()->pools.add(result);
return result;
}
void AliceMemoryPool::deletePool(AliceMemoryPool* pool)
{
AliceGlobals* tdgbl = AliceGlobals::getSpecific();
for (int i = 0; i < tdgbl->pools.getCount(); ++i)
{
if (tdgbl->pools[i] == pool)
{
tdgbl->pools.remove(i);
break;
}
}
MemoryPool::deletePool(pool);
}

View File

@ -24,7 +24,8 @@
#ifndef ALICE_ALL_H
#define ALICE_ALL_H
#include "../jrd/block_cache.h"
#include "../common/classes/auto.h"
#include "../common/classes/alloc.h"
class AliceMemoryPool : public MemoryPool
{
@ -35,7 +36,13 @@ protected:
public:
static AliceMemoryPool* createPool();
static void deletePool(AliceMemoryPool* pool);
static void clear(AliceMemoryPool* ptr)
{
deletePool(ptr);
}
};
typedef Firebird::AutoPtr<AliceMemoryPool, AliceMemoryPool> AliceAutoPool;
#endif // ALICE_ALL_H

View File

@ -24,7 +24,7 @@
//
//____________________________________________________________
//
// $Id: exe.cpp,v 1.37 2004-08-30 18:10:28 alexpeshkoff Exp $
// $Id: exe.cpp,v 1.38 2004-09-01 14:51:33 alexpeshkoff Exp $
//
// 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE"
// conditionals, as the engine now fully supports
@ -82,20 +82,24 @@ static inline void stuff_dpb_long(UCHAR** d, int blr)
//
int EXE_action(const TEXT* database, const ULONG switches)
{
bool error = false;
AliceAutoPool newPool(AliceMemoryPool::createPool());
{
UCHAR dpb[128];
AliceGlobals* tdgbl = AliceGlobals::getSpecific();
AliceContextPoolHolder context(tdgbl, AliceMemoryPool::createPool());
AliceContextPoolHolder context(tdgbl, newPool);
for (USHORT i = 0; i < MAX_VAL_ERRORS; i++)
{
tdgbl->ALICE_data.ua_val_errors[i] = 0;
}
// generate the database parameter block for the attach,
// based on the various switches
const USHORT dpb_length = build_dpb(dpb, switches);
bool error = false;
FB_API_HANDLE handle = 0;
isc_attach_database(tdgbl->status, 0, database, &handle, dpb_length,
reinterpret_cast<SCHAR*>(dpb));
@ -111,11 +115,15 @@ int EXE_action(const TEXT* database, const ULONG switches)
}
if (tdgbl->status[2] == isc_arg_warning)
{
ALICE_print_status(tdgbl->status);
}
if (handle != 0) {
if (handle != 0)
{
UCHAR error_string[128];
if ((switches & sw_validate) && (tdgbl->status[1] != isc_bug_check)) {
if ((switches & sw_validate) && (tdgbl->status[1] != isc_bug_check))
{
isc_database_info(tdgbl->status, &handle, sizeof(val_errors),
val_errors, sizeof(error_string),
reinterpret_cast<char*>(error_string));
@ -124,10 +132,13 @@ int EXE_action(const TEXT* database, const ULONG switches)
}
if (switches & sw_disable)
{
MET_disable_wal(tdgbl->status, handle);
}
isc_detach_database(tdgbl->status, &handle);
}
}
return ((error) ? FINI_ERROR : FINI_OK);
}
@ -138,20 +149,24 @@ int EXE_action(const TEXT* database, const ULONG switches)
//
int EXE_two_phase(const TEXT* database, const ULONG switches)
{
bool error = false;
AliceAutoPool newPool(AliceMemoryPool::createPool());
{
UCHAR dpb[128];
AliceGlobals* tdgbl = AliceGlobals::getSpecific();
AliceContextPoolHolder context(tdgbl, AliceMemoryPool::createPool());
AliceContextPoolHolder context(tdgbl, newPool);
for (USHORT i = 0; i < MAX_VAL_ERRORS; i++)
{
tdgbl->ALICE_data.ua_val_errors[i] = 0;
}
// generate the database parameter block for the attach,
// based on the various switches
const USHORT dpb_length = build_dpb(dpb, switches);
bool error = false;
FB_API_HANDLE handle = 0;
isc_attach_database(tdgbl->status, 0, database, &handle,
dpb_length, reinterpret_cast<char*>(dpb));
@ -159,18 +174,27 @@ int EXE_two_phase(const TEXT* database, const ULONG switches)
tdgbl->service_blk->svc_started();
if (tdgbl->status[1])
{
error = true;
}
else if (switches & sw_list)
{
TDR_list_limbo((handle), database, switches);
}
else if (switches & (sw_commit | sw_rollback | sw_two_phase))
{
error = TDR_reconnect_multiple((handle),
tdgbl->ALICE_data.ua_transaction, database,
switches);
}
if (handle)
{
isc_detach_database(tdgbl->status, &handle);
}
}
return ((error) ? FINI_ERROR : FINI_OK);
return (error ? FINI_ERROR : FINI_OK);
}
//____________________________________________________________

View File

@ -1,33 +0,0 @@
/*
* PROGRAM: Alice
* MODULE: lls.h
* DESCRIPTION: Linked list stack definitions
*
* 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): ______________________________________.
*/
#ifndef ALICE_LLS_H
#define ALICE_LLS_H
struct alice_lls {
struct blk* lls_object;
alice_lls* lls_next;
};
#endif // ALICE_LLS_H