diff --git a/src/alice/alice.cpp b/src/alice/alice.cpp index 4fd2cb91a0..394eb797f7 100644 --- a/src/alice/alice.cpp +++ b/src/alice/alice.cpp @@ -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 diff --git a/src/alice/alice.h b/src/alice/alice.h index e80b961551..b4833d2cb2 100644 --- a/src/alice/alice.h +++ b/src/alice/alice.h @@ -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 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 diff --git a/src/alice/all.cpp b/src/alice/all.cpp index 4a7f8cd46a..60c4291858 100644 --- a/src/alice/all.cpp +++ b/src/alice/all.cpp @@ -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); } diff --git a/src/alice/all.h b/src/alice/all.h index c275b7a872..194a0c9647 100644 --- a/src/alice/all.h +++ b/src/alice/all.h @@ -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 AliceAutoPool; + #endif // ALICE_ALL_H diff --git a/src/alice/exe.cpp b/src/alice/exe.cpp index 6697e0acc7..e08654a0fe 100644 --- a/src/alice/exe.cpp +++ b/src/alice/exe.cpp @@ -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 @@ -83,50 +83,61 @@ static inline void stuff_dpb_long(UCHAR** d, int blr) int EXE_action(const TEXT* database, const ULONG switches) { - UCHAR dpb[128]; - AliceGlobals* tdgbl = AliceGlobals::getSpecific(); - AliceContextPoolHolder context(tdgbl, AliceMemoryPool::createPool()); + bool error = false; + AliceAutoPool newPool(AliceMemoryPool::createPool()); + { + UCHAR dpb[128]; + AliceGlobals* tdgbl = AliceGlobals::getSpecific(); + AliceContextPoolHolder context(tdgbl, newPool); - for (USHORT i = 0; i < MAX_VAL_ERRORS; i++) - tdgbl->ALICE_data.ua_val_errors[i] = 0; + 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); + 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, + FB_API_HANDLE handle = 0; + isc_attach_database(tdgbl->status, 0, database, &handle, dpb_length, reinterpret_cast(dpb)); - tdgbl->service_blk->svc_started(); + tdgbl->service_blk->svc_started(); - if (tdgbl->status[1] && - // Ignore isc_shutdown error produced when we switch to full shutdown mode. It is expected. - (tdgbl->status[1] != isc_shutdown || !(switches & sw_shut) || tdgbl->ALICE_data.ua_shutdown_mode != SHUT_FULL) - ) - { - error = true; - } + if (tdgbl->status[1] && + // Ignore isc_shutdown error produced when we switch to full shutdown mode. It is expected. + (tdgbl->status[1] != isc_shutdown || !(switches & sw_shut) || tdgbl->ALICE_data.ua_shutdown_mode != SHUT_FULL) + ) + { + error = true; + } - if (tdgbl->status[2] == isc_arg_warning) - ALICE_print_status(tdgbl->status); + if (tdgbl->status[2] == isc_arg_warning) + { + ALICE_print_status(tdgbl->status); + } - if (handle != 0) { - UCHAR error_string[128]; - if ((switches & sw_validate) && (tdgbl->status[1] != isc_bug_check)) { - isc_database_info(tdgbl->status, &handle, sizeof(val_errors), + if (handle != 0) + { + UCHAR error_string[128]; + 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(error_string)); - extract_db_info(error_string); + extract_db_info(error_string); + } + + if (switches & sw_disable) + { + MET_disable_wal(tdgbl->status, handle); + } + + isc_detach_database(tdgbl->status, &handle); } - - if (switches & sw_disable) - MET_disable_wal(tdgbl->status, handle); - - isc_detach_database(tdgbl->status, &handle); } return ((error) ? FINI_ERROR : FINI_OK); @@ -139,38 +150,51 @@ int EXE_action(const TEXT* database, const ULONG switches) int EXE_two_phase(const TEXT* database, const ULONG switches) { - UCHAR dpb[128]; - AliceGlobals* tdgbl = AliceGlobals::getSpecific(); - AliceContextPoolHolder context(tdgbl, AliceMemoryPool::createPool()); + bool error = false; + AliceAutoPool newPool(AliceMemoryPool::createPool()); + { + UCHAR dpb[128]; + AliceGlobals* tdgbl = AliceGlobals::getSpecific(); + AliceContextPoolHolder context(tdgbl, newPool); - for (USHORT i = 0; i < MAX_VAL_ERRORS; i++) - tdgbl->ALICE_data.ua_val_errors[i] = 0; + 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); + const USHORT dpb_length = build_dpb(dpb, switches); - bool error = false; - FB_API_HANDLE handle = 0; - isc_attach_database(tdgbl->status, 0, database, &handle, + FB_API_HANDLE handle = 0; + isc_attach_database(tdgbl->status, 0, database, &handle, dpb_length, reinterpret_cast(dpb)); - tdgbl->service_blk->svc_started(); + 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), + 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); + if (handle) + { + isc_detach_database(tdgbl->status, &handle); + } + } - return ((error) ? FINI_ERROR : FINI_OK); + return (error ? FINI_ERROR : FINI_OK); } //____________________________________________________________ diff --git a/src/alice/lls.h b/src/alice/lls.h deleted file mode 100644 index e3d4ac9911..0000000000 --- a/src/alice/lls.h +++ /dev/null @@ -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 -