3939
4040#pragma once
4141
42+ #include < concepts>
4243#include < cstdlib>
4344#include < utility>
4445#include " tscore/ink_queue.h"
@@ -329,11 +330,10 @@ using Allocator = FreelistAllocator;
329330 Allocator for Class objects.
330331
331332*/
332- template <class C , bool Destruct_on_free_ = false , typename BaseAllocator = Allocator> class ClassAllocator : public BaseAllocator
333+ template <std::destructible C , typename BaseAllocator = Allocator> class ClassAllocator : public BaseAllocator
333334{
334335public:
335- using Value_type = C;
336- static bool const Destruct_on_free = Destruct_on_free_;
336+ using Value_type = C;
337337
338338 /* * Allocates objects of the templated type. Arguments are forwarded to the constructor for the object. */
339339 template <typename ... Args>
@@ -380,21 +380,19 @@ template <class C, bool Destruct_on_free_ = false, typename BaseAllocator = Allo
380380 void
381381 destroy_if_enabled (C *ptr)
382382 {
383- if (Destruct_on_free) {
384- ptr->~C ();
385- }
383+ std::destroy_at (ptr);
386384 }
387385
388386 // Ensure that C is big enough to hold a void pointer (when it's stored in the free list as raw memory).
389387 //
390388 static_assert (sizeof (C) >= sizeof (void *), " Can not allocate instances of this class using ClassAllocator" );
391389};
392390
393- template <class C , bool Destruct_on_free = false > class TrackerClassAllocator : public ClassAllocator <C, Destruct_on_free >
391+ template <class C > class TrackerClassAllocator : public ClassAllocator <C>
394392{
395393public:
396394 TrackerClassAllocator (const char *name, unsigned int chunk_size = 128 , unsigned int alignment = 16 )
397- : ClassAllocator<C, Destruct_on_free >(name, chunk_size, alignment), allocations(0 ), trackerLock(PTHREAD_MUTEX_INITIALIZER)
395+ : ClassAllocator<C>(name, chunk_size, alignment), allocations(0 ), trackerLock(PTHREAD_MUTEX_INITIALIZER)
398396 {
399397 }
400398
@@ -403,7 +401,7 @@ template <class C, bool Destruct_on_free = false> class TrackerClassAllocator :
403401 {
404402 void *callstack[3 ];
405403 int frames = backtrace (callstack, 3 );
406- C *ptr = ClassAllocator<C, Destruct_on_free >::alloc ();
404+ C *ptr = ClassAllocator<C>::alloc ();
407405
408406 const void *symbol = nullptr ;
409407 if (frames == 3 && callstack[2 ] != nullptr ) {
@@ -429,7 +427,7 @@ template <class C, bool Destruct_on_free = false> class TrackerClassAllocator :
429427 reverse_lookup.erase (it);
430428 }
431429 ink_mutex_release (&trackerLock);
432- ClassAllocator<C, Destruct_on_free >::free (ptr);
430+ ClassAllocator<C>::free (ptr);
433431 }
434432
435433private:
0 commit comments