From 66af969f5cb68894d6f7167f4115db2c5bb97bcc Mon Sep 17 00:00:00 2001 From: Steve Huston Date: Tue, 14 Sep 2004 15:33:15 +0000 Subject: ChangeLogTag:Tue Sep 14 11:07:25 2004 Steve Huston --- ChangeLog | 12 ++++++++++++ THANKS | 1 + ace/Malloc_T.h | 6 ++++++ ace/Malloc_T.inl | 12 ++++++++++++ tests/Cached_Allocator_Test.cpp | 19 +++++++++++++++++++ 5 files changed, 50 insertions(+) diff --git a/ChangeLog b/ChangeLog index 42905a998bd..87febced38d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Tue Sep 14 11:07:25 2004 Steve Huston + + * ace/Malloc_T.{h inl}: Added ACE_Cached_Allocator<>::pool_depth() + and ACE_Dynamic_Cached_Allocator<>::pool_depth(). Each returns the + number of items in the cache available for allocating. Thank you to + Jeff Jones for this addition. + + * tests/Cached_Allocator_Test.cpp: Added tests of the new pool_depth() + method. + + * THANKS: Added Jeff Jones to the Hall of Fame. + Tue Sep 14 11:58:12 UTC 2004 Johnny Willemsen * ace/Dynamic_Service.h: diff --git a/THANKS b/THANKS index 80dca0de559..edc1ab57d1e 100644 --- a/THANKS +++ b/THANKS @@ -1904,6 +1904,7 @@ Rick Robinson John D. Robertson Paul Lew Eider Oliveira +Jeff Jones I would particularly like to thank Paul Stephenson, who worked with me at Ericsson in the early 1990's. Paul devised the recursive Makefile diff --git a/ace/Malloc_T.h b/ace/Malloc_T.h index ada5fc23236..db31b148fa3 100644 --- a/ace/Malloc_T.h +++ b/ace/Malloc_T.h @@ -115,6 +115,9 @@ public: /// Return a chunk of memory back to free list cache. void free (void *); + /// Return the number of chunks available in the cache. + size_t pool_depth (void); + private: /// Remember how we allocate the memory in the first place so /// we can clear things up later. @@ -177,6 +180,9 @@ public: /// Return a chunk of memory back to free list cache. void free (void *); + /// Return the number of chunks available in the cache. + size_t pool_depth (void); + private: /// Remember how we allocate the memory in the first place so /// we can clear things up later. diff --git a/ace/Malloc_T.inl b/ace/Malloc_T.inl index b24436fb868..109d1153336 100644 --- a/ace/Malloc_T.inl +++ b/ace/Malloc_T.inl @@ -67,6 +67,12 @@ ACE_Cached_Allocator::free (void * ptr) this->free_list_.add ((ACE_Cached_Mem_Pool_Node *) ptr) ; } +template ACE_INLINE size_t +ACE_Cached_Allocator::pool_depth (void) +{ + return this->free_list_.size (); +} + template ACE_INLINE void * ACE_Dynamic_Cached_Allocator::malloc (size_t nbytes) { @@ -107,6 +113,12 @@ ACE_Dynamic_Cached_Allocator::free (void * ptr) this->free_list_.add ((ACE_Cached_Mem_Pool_Node *) ptr); } +template ACE_INLINE size_t +ACE_Dynamic_Cached_Allocator::pool_depth (void) +{ + return this->free_list_.size (); +} + template ACE_INLINE void * ACE_Allocator_Adapter::malloc (size_t nbytes) { diff --git a/tests/Cached_Allocator_Test.cpp b/tests/Cached_Allocator_Test.cpp index 0e5bcf5f28f..78cab3e70e4 100644 --- a/tests/Cached_Allocator_Test.cpp +++ b/tests/Cached_Allocator_Test.cpp @@ -149,6 +149,7 @@ run_main (int argc, ACE_TCHAR *argv[]) size_t chunk_size = 0; size_t n_chunks = 0; size_t requested_size = 0; + size_t depth = 0; char *ptr1 = 0; char *ptr2 = 0; char *ptr3 = 0; @@ -174,6 +175,12 @@ run_main (int argc, ACE_TCHAR *argv[]) DYNAMIC_ALLOCATOR allocator (n_chunks, chunk_size); + if ((depth = allocator.pool_depth ()) != n_chunks) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Expected pool depth ") ACE_SIZE_T_FORMAT_SPECIFIER + ACE_TEXT (" but reported ") ACE_SIZE_T_FORMAT_SPECIFIER + ACE_TEXT ("\n"), + n_chunks, depth)); requested_size = chunk_size; ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Allocating chunk 1: %d bytes, should succeed...\n"), @@ -184,6 +191,12 @@ run_main (int argc, ACE_TCHAR *argv[]) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" (%t) Failed, exiting.\n")), -1); ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) OK, succeeded.\n"))); + if ((depth = allocator.pool_depth ()) != (n_chunks - 1)) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Expected pool depth ") ACE_SIZE_T_FORMAT_SPECIFIER + ACE_TEXT (" but reported ") ACE_SIZE_T_FORMAT_SPECIFIER + ACE_TEXT ("\n"), + n_chunks - 1, depth)); requested_size = chunk_size + 1; ACE_DEBUG ((LM_INFO, @@ -208,6 +221,12 @@ run_main (int argc, ACE_TCHAR *argv[]) ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) OK, succeeded.\n"))); // One chunk too far... + if ((depth = allocator.pool_depth ()) != 0) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Expected pool depth 0") + ACE_TEXT (" but reported ") ACE_SIZE_T_FORMAT_SPECIFIER + ACE_TEXT ("\n"), + depth)); requested_size = chunk_size; ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Allocating chunk 4: %d bytes, no free chunks,") -- cgit v1.2.1