From a3efa9612f9e0179dd4ea80de65d46ce711d72b8 Mon Sep 17 00:00:00 2001 From: hno <> Date: Sun, 3 Sep 2006 10:11:59 +0000 Subject: [PATCH] Cleanup of some MemAllocatorProxy abuse. This is a MemPool internal class, only meant to be used via the CLASS macros. --- include/MemPool.h | 1 + lib/MemPool.cc | 15 +++-- .../DiskThreads/DiskThreadsIOStrategy.cc | 6 +- .../DiskThreads/DiskThreadsIOStrategy.h | 4 +- src/DiskIO/DiskThreads/aiops.cc | 55 +++++++++---------- src/auth/digest/auth_digest.cc | 6 +- src/auth/negotiate/auth_negotiate.cc | 12 +--- src/auth/ntlm/auth_ntlm.cc | 11 +--- src/fs/coss/StoreFScoss.cc | 4 +- src/fs/coss/store_coss.h | 4 +- src/fs/coss/store_dir_coss.cc | 4 +- src/helper.h | 4 +- src/repl/lru/store_repl_lru.cc | 6 +- test-suite/MemPoolTest.cc | 6 +- 14 files changed, 60 insertions(+), 78 deletions(-) diff --git a/include/MemPool.h b/include/MemPool.h index 68cfb27be9..b1f6218d94 100644 --- a/include/MemPool.h +++ b/include/MemPool.h @@ -109,6 +109,7 @@ public: virtual void free(void *) = 0; virtual char const *objectType() const; virtual size_t objectSize() const = 0; + int inUseCount(); private: const char *label; }; diff --git a/lib/MemPool.cc b/lib/MemPool.cc index 85d51e2d28..5de67f74f5 100644 --- a/lib/MemPool.cc +++ b/lib/MemPool.cc @@ -1,6 +1,6 @@ /* - * $Id: MemPool.cc,v 1.4 2006/09/03 04:09:35 hno Exp $ + * $Id: MemPool.cc,v 1.5 2006/09/03 04:11:59 hno Exp $ * * DEBUG: section 63 Low Level Memory Pool Management * AUTHOR: Alex Rousskov, Andres Kroonmaa, Robert Collins @@ -453,6 +453,14 @@ MemAllocator::objectType() const return label; } +int +MemAllocator::inUseCount() +{ + MemPoolStats stats; + getStats(&stats); + return stats.items_inuse; +} + void MemImplementingAllocator::flushMeters() { @@ -832,10 +840,7 @@ MemMalloc::clean(time_t maxage) int memPoolInUseCount(MemAllocator * pool) { - MemPoolStats stats; - assert(pool != NULL); - pool->getStats(&stats); - return stats.items_inuse; + return pool->inUseCount(); } int diff --git a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc index 2fb68c856c..6d7f42c997 100644 --- a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc +++ b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc @@ -1,6 +1,6 @@ /* - * $Id: DiskThreadsIOStrategy.cc,v 1.7 2006/06/17 16:36:15 serassio Exp $ + * $Id: DiskThreadsIOStrategy.cc,v 1.8 2006/09/03 04:12:00 hno Exp $ * * DEBUG: section 79 Squid-side Disk I/O functions. * AUTHOR: Robert Collins @@ -43,15 +43,13 @@ #include "Store.h" #include "fde.h" -//static MemAllocatorProxy *squidaio_ctrl_pool; - void DiskThreadsIOStrategy::init(void) { if (initialised) return; - squidaio_ctrl_pool = new MemAllocatorProxy("aio_ctrl", sizeof(squidaio_ctrl_t)); + squidaio_ctrl_pool = MemPools::GetInstance().create("aio_ctrl", sizeof(squidaio_ctrl_t)); initialised = true; diff --git a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.h b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.h index 56e8199fe6..1bea5092b8 100644 --- a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.h +++ b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.h @@ -1,6 +1,6 @@ /* - * $Id: DiskThreadsIOStrategy.h,v 1.3 2006/05/29 00:15:03 robertc Exp $ + * $Id: DiskThreadsIOStrategy.h,v 1.4 2006/09/03 04:12:00 hno Exp $ * * DEBUG: section 79 Squid-side Disk I/O functions. * AUTHOR: Robert Collins @@ -64,7 +64,7 @@ public: /* Todo: add access limitations */ bool initialised; static DiskThreadsIOStrategy Instance; - MemAllocatorProxy *squidaio_ctrl_pool; + MemAllocator *squidaio_ctrl_pool; private: static void aioStats(StoreEntry * sentry); diff --git a/src/DiskIO/DiskThreads/aiops.cc b/src/DiskIO/DiskThreads/aiops.cc index 72d52fc208..314ec65e6b 100644 --- a/src/DiskIO/DiskThreads/aiops.cc +++ b/src/DiskIO/DiskThreads/aiops.cc @@ -1,5 +1,5 @@ /* - * $Id: aiops.cc,v 1.10 2006/08/07 02:28:22 robertc Exp $ + * $Id: aiops.cc,v 1.11 2006/09/03 04:12:01 hno Exp $ * * DEBUG: section 43 AIOPS * AUTHOR: Stewart Forster @@ -143,15 +143,15 @@ static int squidaio_initialised = 0; #define AIO_TINY_BUFS AIO_LARGE_BUFS >> 3 #define AIO_MICRO_BUFS 128 -static MemAllocatorProxy *squidaio_large_bufs = NULL; /* 16K */ -static MemAllocatorProxy *squidaio_medium_bufs = NULL; /* 8K */ -static MemAllocatorProxy *squidaio_small_bufs = NULL; /* 4K */ -static MemAllocatorProxy *squidaio_tiny_bufs = NULL; /* 2K */ -static MemAllocatorProxy *squidaio_micro_bufs = NULL; /* 128K */ +static MemAllocator *squidaio_large_bufs = NULL; /* 16K */ +static MemAllocator *squidaio_medium_bufs = NULL; /* 8K */ +static MemAllocator *squidaio_small_bufs = NULL; /* 4K */ +static MemAllocator *squidaio_tiny_bufs = NULL; /* 2K */ +static MemAllocator *squidaio_micro_bufs = NULL; /* 128K */ static int request_queue_len = 0; -static MemAllocatorProxy *squidaio_request_pool = NULL; -static MemAllocatorProxy *squidaio_thread_pool = NULL; +static MemAllocator *squidaio_request_pool = NULL; +static MemAllocator *squidaio_thread_pool = NULL; static squidaio_request_queue_t request_queue; static struct @@ -181,33 +181,30 @@ static struct sched_param globsched; #endif static pthread_t main_thread; -static MemAllocatorProxy * +static MemAllocator * squidaio_get_pool(int size) { - MemAllocatorProxy *p; - if (size <= AIO_LARGE_BUFS) { if (size <= AIO_MICRO_BUFS) - p = squidaio_micro_bufs; + return squidaio_micro_bufs; else if (size <= AIO_TINY_BUFS) - p = squidaio_tiny_bufs; + return squidaio_tiny_bufs; else if (size <= AIO_SMALL_BUFS) - p = squidaio_small_bufs; + return squidaio_small_bufs; else if (size <= AIO_MEDIUM_BUFS) - p = squidaio_medium_bufs; + return squidaio_medium_bufs; else - p = squidaio_large_bufs; - } else - p = NULL; + return squidaio_large_bufs; + } - return p; + return NULL; } void * squidaio_xmalloc(int size) { void *p; - MemAllocatorProxy *pool; + MemAllocator *pool; if ((pool = squidaio_get_pool(size)) != NULL) { p = pool->alloc(); @@ -232,7 +229,7 @@ squidaio_xstrdup(const char *str) void squidaio_xfree(void *p, int size) { - MemAllocatorProxy *pool; + MemAllocator *pool; if ((pool = squidaio_get_pool(size)) != NULL) { pool->free(p); @@ -243,7 +240,7 @@ squidaio_xfree(void *p, int size) static void squidaio_xstrfree(char *str) { - MemAllocatorProxy *pool; + MemAllocator *pool; int len = strlen(str) + 1; if ((pool = squidaio_get_pool(len)) != NULL) { @@ -326,7 +323,7 @@ squidaio_init(void) done_queue.blocked = 0; /* Create threads and get them to sit in their wait loop */ - squidaio_thread_pool = new MemAllocatorProxy("aio_thread", sizeof(squidaio_thread_t)); + squidaio_thread_pool = MemPools::GetInstance().create("aio_thread", sizeof(squidaio_thread_t)); assert(NUMTHREADS); @@ -346,17 +343,17 @@ squidaio_init(void) } /* Create request pool */ - squidaio_request_pool = new MemAllocatorProxy("aio_request", sizeof(squidaio_request_t)); + squidaio_request_pool = MemPools::GetInstance().create("aio_request", sizeof(squidaio_request_t)); - squidaio_large_bufs = new MemAllocatorProxy("squidaio_large_bufs", AIO_LARGE_BUFS); + squidaio_large_bufs = MemPools::GetInstance().create("squidaio_large_bufs", AIO_LARGE_BUFS); - squidaio_medium_bufs = new MemAllocatorProxy("squidaio_medium_bufs", AIO_MEDIUM_BUFS); + squidaio_medium_bufs = MemPools::GetInstance().create("squidaio_medium_bufs", AIO_MEDIUM_BUFS); - squidaio_small_bufs = new MemAllocatorProxy("squidaio_small_bufs", AIO_SMALL_BUFS); + squidaio_small_bufs = MemPools::GetInstance().create("squidaio_small_bufs", AIO_SMALL_BUFS); - squidaio_tiny_bufs = new MemAllocatorProxy("squidaio_tiny_bufs", AIO_TINY_BUFS); + squidaio_tiny_bufs = MemPools::GetInstance().create("squidaio_tiny_bufs", AIO_TINY_BUFS); - squidaio_micro_bufs = new MemAllocatorProxy("squidaio_micro_bufs", AIO_MICRO_BUFS); + squidaio_micro_bufs = MemPools::GetInstance().create("squidaio_micro_bufs", AIO_MICRO_BUFS); squidaio_initialised = 1; } diff --git a/src/auth/digest/auth_digest.cc b/src/auth/digest/auth_digest.cc index e79a57e46a..47c1078475 100644 --- a/src/auth/digest/auth_digest.cc +++ b/src/auth/digest/auth_digest.cc @@ -1,6 +1,6 @@ /* - * $Id: auth_digest.cc,v 1.48 2006/08/07 02:28:24 robertc Exp $ + * $Id: auth_digest.cc,v 1.49 2006/09/03 04:12:01 hno Exp $ * * DEBUG: section 29 Authenticator * AUTHOR: Robert Collins @@ -63,7 +63,7 @@ static hash_table *digest_nonce_cache; static AuthDigestConfig digestConfig; static int authdigest_initialised = 0; -static MemAllocatorProxy *digest_nonce_pool = NULL; +static MemAllocator *digest_nonce_pool = NULL; CBDATA_TYPE(DigestAuthenticateStateData); @@ -201,7 +201,7 @@ static void authenticateDigestNonceSetup(void) { if (!digest_nonce_pool) - digest_nonce_pool = new MemAllocatorProxy("Digest Scheme nonce's", sizeof(digest_nonce_h)); + digest_nonce_pool = MemPools::GetInstance().create("Digest Scheme nonce's", sizeof(digest_nonce_h)); if (!digest_nonce_cache) { digest_nonce_cache = hash_create((HASHCMP *) strcmp, 7921, hash_string); diff --git a/src/auth/negotiate/auth_negotiate.cc b/src/auth/negotiate/auth_negotiate.cc index 428306a9ae..0ca74aebea 100644 --- a/src/auth/negotiate/auth_negotiate.cc +++ b/src/auth/negotiate/auth_negotiate.cc @@ -1,6 +1,6 @@ /* - * $Id: auth_negotiate.cc,v 1.10 2006/07/07 19:10:30 serassio Exp $ + * $Id: auth_negotiate.cc,v 1.11 2006/09/03 04:12:01 hno Exp $ * * DEBUG: section 29 Negotiate Authenticator * AUTHOR: Robert Collins, Henrik Nordstrom, Francesco Chemolli @@ -70,8 +70,6 @@ CBDATA_TYPE(authenticateStateData); static int authnegotiate_initialised = 0; -//static MemAllocatorProxy *negotiate_user_hash_pool = NULL; - static auth_negotiate_config negotiateConfig; static hash_table *proxy_auth_cache = NULL; @@ -175,14 +173,6 @@ void AuthNegotiateConfig::init(AuthConfig * scheme) { if (authenticate) { -#if PLACEHOLDER - - if (!negotiate_user_hash_pool) - - negotiate_user_hash_pool = new MemAllocatorProxy("Negotiate Header Hash Data", sizeof(struct ProxyAuthCachePointer)); - -#endif - authnegotiate_initialised = 1; if (negotiateauthenticators == NULL) diff --git a/src/auth/ntlm/auth_ntlm.cc b/src/auth/ntlm/auth_ntlm.cc index 0436ecebb8..5ff7d549c1 100644 --- a/src/auth/ntlm/auth_ntlm.cc +++ b/src/auth/ntlm/auth_ntlm.cc @@ -1,6 +1,6 @@ /* - * $Id: auth_ntlm.cc,v 1.59 2006/07/07 19:10:30 serassio Exp $ + * $Id: auth_ntlm.cc,v 1.60 2006/09/03 04:12:02 hno Exp $ * * DEBUG: section 29 NTLM Authenticator * AUTHOR: Robert Collins, Henrik Nordstrom, Francesco Chemolli @@ -70,8 +70,6 @@ CBDATA_TYPE(authenticateStateData); static int authntlm_initialised = 0; -//static MemAllocatorProxy *ntlm_user_hash_pool = NULL; - static auth_ntlm_config ntlmConfig; static hash_table *proxy_auth_cache = NULL; @@ -175,13 +173,6 @@ void AuthNTLMConfig::init(AuthConfig * scheme) { if (authenticate) { -#if PLACEHOLDER - - if (!ntlm_user_hash_pool) - - ntlm_user_hash_pool = new MemAllocatorProxy("NTLM Header Hash Data", sizeof(struct ProxyAuthCachePointer)); - -#endif authntlm_initialised = 1; diff --git a/src/fs/coss/StoreFScoss.cc b/src/fs/coss/StoreFScoss.cc index 832edda8e3..2a0ed9771f 100644 --- a/src/fs/coss/StoreFScoss.cc +++ b/src/fs/coss/StoreFScoss.cc @@ -1,6 +1,6 @@ /* - * $Id: StoreFScoss.cc,v 1.5 2006/05/29 00:15:09 robertc Exp $ + * $Id: StoreFScoss.cc,v 1.6 2006/09/03 04:12:02 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Robert Collins @@ -79,7 +79,7 @@ StoreFScoss::setup() { assert(!initialised); - coss_index_pool = new MemAllocatorProxy("COSS index data", sizeof(CossIndexNode)); + coss_index_pool = MemPools::GetInstance().create("COSS index data", sizeof(CossIndexNode)); initialised = true; } diff --git a/src/fs/coss/store_coss.h b/src/fs/coss/store_coss.h index 2b058f5c2d..a97ab8069a 100644 --- a/src/fs/coss/store_coss.h +++ b/src/fs/coss/store_coss.h @@ -98,8 +98,8 @@ typedef struct _cossindex CossIndexNode; /* Whether the coss system has been setup or not */ extern int coss_initialised; -extern MemAllocatorProxy *coss_membuf_pool; -extern MemAllocatorProxy *coss_index_pool; +extern MemAllocator *coss_membuf_pool; +extern MemAllocator *coss_index_pool; #include "DiskIO/ReadRequest.h" diff --git a/src/fs/coss/store_dir_coss.cc b/src/fs/coss/store_dir_coss.cc index 4445cecd8c..c4fdc6b7e4 100644 --- a/src/fs/coss/store_dir_coss.cc +++ b/src/fs/coss/store_dir_coss.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.cc,v 1.66 2006/08/19 12:31:21 robertc Exp $ + * $Id: store_dir_coss.cc,v 1.67 2006/09/03 04:12:03 hno Exp $ * vim: set et : * * DEBUG: section 47 Store COSS Directory Routines @@ -54,7 +54,7 @@ int n_coss_dirs = 0; /* static int last_coss_pick_index = -1; */ -MemAllocatorProxy *coss_index_pool = NULL; +MemAllocator *coss_index_pool = NULL; typedef struct _RebuildState RebuildState; diff --git a/src/helper.h b/src/helper.h index a4f6abb2c7..327febd572 100644 --- a/src/helper.h +++ b/src/helper.h @@ -1,6 +1,6 @@ /* - * $Id: helper.h,v 1.5 2006/09/02 15:24:08 serassio Exp $ + * $Id: helper.h,v 1.6 2006/09/03 04:11:59 hno Exp $ * * DEBUG: section 84 Helper process maintenance * AUTHOR: Harvest Derived? @@ -90,7 +90,7 @@ struct _helper_stateful int n_running; int n_active; int ipc_type; - MemAllocatorProxy *datapool; + MemAllocator *datapool; HLPSAVAIL *IsAvailable; HLPSONEQ *OnEmptyQueue; time_t last_queue_warn; diff --git a/src/repl/lru/store_repl_lru.cc b/src/repl/lru/store_repl_lru.cc index 61f1b18421..a93d188b4f 100644 --- a/src/repl/lru/store_repl_lru.cc +++ b/src/repl/lru/store_repl_lru.cc @@ -1,6 +1,6 @@ /* - * $Id: store_repl_lru.cc,v 1.18 2006/08/21 00:50:47 robertc Exp $ + * $Id: store_repl_lru.cc,v 1.19 2006/09/03 04:12:04 hno Exp $ * * DEBUG: section ? LRU Removal policy * AUTHOR: Henrik Nordstrom @@ -97,7 +97,7 @@ struct _LruNode dlink_node node; }; -static MemPool *lru_node_pool = NULL; +static MemImplementingAllocator *lru_node_pool = NULL; static int nr_lru_policies = 0; static void @@ -334,7 +334,7 @@ createRemovalPolicy_lru(wordlist * args) if (!lru_node_pool) { /* Must be chunked */ - lru_node_pool = new MemPool("LRU policy node", sizeof(LruNode)); + lru_node_pool = MemPools::GetInstance().create("LRU policy node", sizeof(LruNode)); lru_node_pool->setChunkSize(512 * 1024); } diff --git a/test-suite/MemPoolTest.cc b/test-suite/MemPoolTest.cc index 8aa48ad51e..a41c178c77 100644 --- a/test-suite/MemPoolTest.cc +++ b/test-suite/MemPoolTest.cc @@ -1,5 +1,5 @@ /* - * $Id: MemPoolTest.cc,v 1.3 2004/08/30 05:12:33 robertc Exp $ + * $Id: MemPoolTest.cc,v 1.4 2006/09/03 04:12:04 hno Exp $ * * AUTHOR: Robert Collins * @@ -54,13 +54,13 @@ private: }; static MemPool *Pool; }; -MemPool *MemPoolTest::Pool = NULL; +MemAllocator *MemPoolTest::Pool = NULL; void MemPoolTest::run() { assert (Pool == NULL); - Pool = new MemPool ("Test Pool", sizeof(SomethingToAlloc)); + Pool = MemPools::GetInstance().create("Test Pool", sizeof(SomethingToAlloc)); assert (Pool); SomethingToAlloc *something = static_cast(Pool->alloc()); assert (something); -- 2.47.2