From e48b2468d7bcdd9fb16791029964a710ba11bbec Mon Sep 17 00:00:00 2001 From: tamlin Date: Fri, 28 Dec 2001 05:16:31 +0000 Subject: [PATCH] MemoryPool work --- src/alice/alice.cpp | 14 +++++++------- src/alice/alice.h | 4 ++-- src/alice/all.cpp | 10 ++++++---- src/alice/all.h | 2 +- src/common/memory/allocators.cpp | 11 ++++++++++- src/common/memory/allocators.h | 16 +++++++--------- src/common/memory/memory_pool.h | 8 +++++--- src/dsql/all.h | 2 +- src/dsql/alld.cpp | 2 +- src/include/firebird.h | 10 ++++++++-- src/jrd/all.h | 2 +- src/jrd/jrd.cpp | 2 +- src/jrd/met.epp | 8 ++++---- src/jrd/rse.cpp | 4 ++-- src/jrd/svc.cpp | 2 +- 15 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/alice/alice.cpp b/src/alice/alice.cpp index 475483691c..52e7cf02f7 100644 --- a/src/alice/alice.cpp +++ b/src/alice/alice.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: alice.cpp,v 1.8 2001-12-25 08:01:58 tamlin Exp $ +// $Id: alice.cpp,v 1.9 2001-12-28 05:14:41 tamlin Exp $ // // 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" // conditionals, as the engine now fully supports @@ -38,18 +38,18 @@ #define FB_FROM_ALICE_CPP -#include "../jrd/ib_stdio.h" -#include "../jrd/gds.h" -#include "../jrd/common.h" -#include "../jrd/license.h" -#include "../jrd/ibsetjmp.h" -#include "../jrd/msg_encode.h" #include "../alice/alice.h" #include "../alice/aliceswi.h" #include "../alice/all.h" #include "../alice/alice_proto.h" #include "../alice/all_proto.h" #include "../alice/exe_proto.h" +#include "../jrd/ib_stdio.h" +#include "../jrd/gds.h" +#include "../jrd/common.h" +#include "../jrd/license.h" +#include "../jrd/ibsetjmp.h" +#include "../jrd/msg_encode.h" #include "../jrd/gds_proto.h" #include "../jrd/svc.h" #include "../jrd/svc_proto.h" diff --git a/src/alice/alice.h b/src/alice/alice.h index 9d2cded346..1983e66e0a 100644 --- a/src/alice/alice.h +++ b/src/alice/alice.h @@ -203,8 +203,8 @@ extern struct tgbl *gdgbl; #define GET_THREAD_DATA (gdgbl) #ifdef __cplusplus -#define SET_THREAD_DATA gdgbl = tdgbl; \ - tdgbl->tgbl_thd_data.thdd_type = const_cast(THDD_TYPE_TGBL) +#define SET_THREAD_DATA gdgbl = const_cast(tdgbl); \ + tdgbl->tgbl_thd_data.thdd_type = THDD_TYPE_TGBL #else #define SET_THREAD_DATA gdgbl = tdgbl; \ tdgbl->tgbl_thd_data.thdd_type = THDD_TYPE_TGBL diff --git a/src/alice/all.cpp b/src/alice/all.cpp index c61218f1ee..3a26da2b99 100644 --- a/src/alice/all.cpp +++ b/src/alice/all.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: all.cpp,v 1.3 2001-12-24 02:50:47 tamlin Exp $ +// $Id: all.cpp,v 1.4 2001-12-28 05:14:41 tamlin Exp $ // #include "../alice/all.h" @@ -59,7 +59,8 @@ void ALLA_fini(void) } tdgbl->pools.clear(); - tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = NULL; + tdgbl->ALICE_default_pool = 0; + tdgbl->ALICE_permanent_pool = 0; } @@ -78,8 +79,9 @@ void ALLA_init(void) tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = AliceMemoryPool::create_new_pool(); #else - tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = - new(*FB_MemoryPool) AliceMemoryPool; + // TMN: John, what pool to use here? + tdgbl->ALICE_permanent_pool = new AliceMemoryPool; + tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool; #endif } diff --git a/src/alice/all.h b/src/alice/all.h index 45732a847e..1c804d56fb 100644 --- a/src/alice/all.h +++ b/src/alice/all.h @@ -39,7 +39,7 @@ public: // : MemoryPool(0, p), // lls_cache(*this) // {} - AliceMemoryPool(int extSize = 0, MemoryPool* p = FB_MemoryPool) + AliceMemoryPool(int extSize = 0, MemoryPool* p = getDefaultMemoryPool()) : MemoryPool(extSize, p), lls_cache(*this) { diff --git a/src/common/memory/allocators.cpp b/src/common/memory/allocators.cpp index 25722087ce..00a4f1fbb8 100644 --- a/src/common/memory/allocators.cpp +++ b/src/common/memory/allocators.cpp @@ -31,6 +31,15 @@ #include "../../jrd/gdsassert.h" #include + +static MemoryPool* FB_MemoryPool = 0; + +MemoryPool* getDefaultMemoryPool() +{ + return FB_MemoryPool; +} + + class InitMemoryPool { public: @@ -57,7 +66,7 @@ private: }; }; -MemoryPool *FB_MemoryPool = 0; + static InitMemoryPool poolLoader; static int badNewCount = 0; diff --git a/src/common/memory/allocators.h b/src/common/memory/allocators.h index 2567a7c8a5..34b634d856 100644 --- a/src/common/memory/allocators.h +++ b/src/common/memory/allocators.h @@ -42,18 +42,16 @@ void* API_ROUTINE gds__alloc(SLONG size_request); extern ULONG API_ROUTINE gds__free(void* blk); }; -extern MemoryPool *FB_MemoryPool; - void* operator new(size_t); void* operator new[](size_t); -void* operator new(size_t, MemoryPool&); -void operator delete(void* mem, MemoryPool&); -void* operator new[](size_t s, MemoryPool&); -void operator delete[](void* mem, MemoryPool&); +FB_DLL_EXPORT void* operator new(size_t, MemoryPool&); +FB_DLL_EXPORT void operator delete(void* mem, MemoryPool&); +FB_DLL_EXPORT void* operator new[](size_t s, MemoryPool&); +FB_DLL_EXPORT void operator delete[](void* mem, MemoryPool&); -void* operator new(size_t, MemoryPool*); -void* operator new[](size_t s, MemoryPool*); +FB_DLL_EXPORT void* operator new(size_t, MemoryPool*); +FB_DLL_EXPORT void* operator new[](size_t s, MemoryPool*); void operator delete(void* mem); void operator delete[](void* mem); @@ -100,7 +98,7 @@ namespace Firebird typedef T value_type; allocator(MemoryPool& p, SSHORT t = 0) : pool(&p), type(t) {} - allocator(MemoryPool *p = FB_MemoryPool, SSHORT t = 0) : pool(p), type(t) {} + allocator(MemoryPool *p = getDefaultMemoryPool(), SSHORT t = 0) : pool(p), type(t) {} pointer allocate(size_type s, const void * = 0) { return (pointer) (pool ? pool->allocate(sizeof(T) * s) : gds__alloc(sizeof(T)*s)); } diff --git a/src/common/memory/memory_pool.h b/src/common/memory/memory_pool.h index ba15733e80..843d8b2678 100644 --- a/src/common/memory/memory_pool.h +++ b/src/common/memory/memory_pool.h @@ -27,10 +27,12 @@ #ifndef MEMORY_POOL_H #define MEMORY_POOL_H -#include "../include/fb_types.h" +#include "../../include/firebird.h" +#include "../../include/fb_types.h" #include "../jrd/ib_stdio.h" -extern class MemoryPool *FB_MemoryPool; + +FB_DLL_EXPORT class MemoryPool* getDefaultMemoryPool(); /** For various reasons Firebird has chosen to do its own heap management. @@ -79,7 +81,7 @@ extern class MemoryPool *FB_MemoryPool; If any memory operation fail an exception is raised. **/ -class MemoryPool +class FB_DLL_EXPORT MemoryPool { public: MemoryPool(size_t = 0, MemoryPool* = 0); diff --git a/src/dsql/all.h b/src/dsql/all.h index defe5ec6e3..03dd1de0cf 100644 --- a/src/dsql/all.h +++ b/src/dsql/all.h @@ -34,7 +34,7 @@ void ALLD_fini(); /* get rid of everything */ class DsqlMemoryPool : public MemoryPool { public: - DsqlMemoryPool(int extSize = 0, MemoryPool& p = *FB_MemoryPool); + DsqlMemoryPool(int extSize = 0, MemoryPool& p = *getDefaultMemoryPool()); ~DsqlMemoryPool(); static class blk* ALLD_pop(class dsql_lls**); diff --git a/src/dsql/alld.cpp b/src/dsql/alld.cpp index 0fa7108f65..a4a91adfa2 100644 --- a/src/dsql/alld.cpp +++ b/src/dsql/alld.cpp @@ -113,7 +113,7 @@ void ALLD_init() if (!init_flag) { init_flag = true; - DSQL_permanent_pool = new(*FB_MemoryPool) DsqlMemoryPool; + DSQL_permanent_pool = new(*getDefaultMemoryPool()) DsqlMemoryPool; pools = new(*DSQL_permanent_pool) Firebird::vector (10, *DSQL_permanent_pool, dsql_type_vec); tdsql->tsql_default = DSQL_permanent_pool; diff --git a/src/include/firebird.h b/src/include/firebird.h index a9e288e917..42dc84cd01 100644 --- a/src/include/firebird.h +++ b/src/include/firebird.h @@ -26,17 +26,23 @@ * * Contributor(s): * Mark O'Donohue - * Mike Nordel + * Mike Nordell * John Bellardo * * - * $Id: firebird.h,v 1.2 2001-12-24 02:50:49 tamlin Exp $ + * $Id: firebird.h,v 1.3 2001-12-28 05:15:46 tamlin Exp $ * */ #include "gen/autoconfig.h" +#if defined(WIN32) || defined(_WIN32) +#define FB_DLL_EXPORT __declspec(dllexport) +#else +#define FB_DLL_EXPORT +#endif + #ifdef __cplusplus #include "fb_exception.h" #endif diff --git a/src/jrd/all.h b/src/jrd/all.h index 52cc489642..31f6b5dd0d 100644 --- a/src/jrd/all.h +++ b/src/jrd/all.h @@ -43,7 +43,7 @@ void ALL_check_memory(void); class JrdMemoryPool : public MemoryPool { public: - JrdMemoryPool(int extSize = 0, MemoryPool* p = FB_MemoryPool) + JrdMemoryPool(int extSize = 0, MemoryPool* p = getDefaultMemoryPool()) : MemoryPool(extSize, p), plb_buckets(0), plb_segments(0), diff --git a/src/jrd/jrd.cpp b/src/jrd/jrd.cpp index a3a92749d7..6d44eed8a0 100644 --- a/src/jrd/jrd.cpp +++ b/src/jrd/jrd.cpp @@ -5374,7 +5374,7 @@ static DBB init(TDBB tdbb, try { - JrdMemoryPool* perm = new(*FB_MemoryPool) JrdMemoryPool; + JrdMemoryPool* perm = new(*getDefaultMemoryPool()) JrdMemoryPool; dbb_ = dbb::newDbb(*perm); //temp.blk_type = type_dbb; dbb_->dbb_permanent = perm; diff --git a/src/jrd/met.epp b/src/jrd/met.epp index 7dfd3e6445..ef55b8b89d 100644 --- a/src/jrd/met.epp +++ b/src/jrd/met.epp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: met.epp,v 1.3 2001-12-24 02:50:51 tamlin Exp $ +$Id: met.epp,v 1.4 2001-12-28 05:16:31 tamlin Exp $ */ // This MUST be at the top of the file #ifdef DARWIN @@ -2195,7 +2195,7 @@ void MET_parse_sys_trigger(TDBB tdbb, REL relation) ((trig_flags & TRG_ignore_perm) ? csb_ignore_perm : 0); old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool; + tdbb->tdbb_default = new(*getDefaultMemoryPool()) JrdMemoryPool; PAR_blr(tdbb, relation, const_cast(blr), @@ -2520,7 +2520,7 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags) } old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool; + tdbb->tdbb_default = new(*getDefaultMemoryPool()) JrdMemoryPool; csb_ = Csb::newCsb(*tdbb->tdbb_default, 5); csb_->csb_rpt.resize(5); // vec always allocates one too many csb_->csb_count = 5; @@ -3441,7 +3441,7 @@ static void get_trigger( return; old_pool = tdbb->tdbb_default; - tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool; + tdbb->tdbb_default = new(*getDefaultMemoryPool()) JrdMemoryPool; MET_parse_blob( tdbb, relation, blob_id, diff --git a/src/jrd/rse.cpp b/src/jrd/rse.cpp index 6e22adbcc3..84156b7134 100644 --- a/src/jrd/rse.cpp +++ b/src/jrd/rse.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: rse.cpp,v 1.4 2001-12-24 02:50:52 tamlin Exp $ +$Id: rse.cpp,v 1.5 2001-12-28 05:16:31 tamlin Exp $ */ #include "firebird.h" @@ -3746,7 +3746,7 @@ static void write_merge_block(TDBB tdbb, MFB mfb, ULONG block) SFB sfb_; if (!(sfb_ = mfb->mfb_sfb)) { - sfb_ = mfb->mfb_sfb = new(*FB_MemoryPool) sfb; + sfb_ = mfb->mfb_sfb = new(*getDefaultMemoryPool()) sfb; } if (!sfb_->sfb_file_name) { TEXT file_name[128]; diff --git a/src/jrd/svc.cpp b/src/jrd/svc.cpp index 33fa1ff043..ebfd21df6d 100644 --- a/src/jrd/svc.cpp +++ b/src/jrd/svc.cpp @@ -602,7 +602,7 @@ SVC SVC_attach(USHORT service_length, we cannot use the JRD allocator. */ // service = (SVC) gds__alloc((SLONG) (sizeof(struct svc))); - service = new(*FB_MemoryPool) svc; + service = new(*getDefaultMemoryPool()) svc; /* FREE: by SETJMP handler */ if (!service) ERR_post(isc_virmemexh, 0);