Skip to content

Commit e9489e2

Browse files
committed
Update ClassAllocator to require and call destructors on ClassAllocated objects
1 parent 734f992 commit e9489e2

File tree

12 files changed

+350
-20
lines changed

12 files changed

+350
-20
lines changed

include/proxy/http/Http1ClientSession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ class Http1ClientSession : public ProxySession
130130
Http1ClientTransaction trans;
131131
};
132132

133-
extern ClassAllocator<Http1ClientSession, true> http1ClientSessionAllocator;
133+
extern ClassAllocator<Http1ClientSession> http1ClientSessionAllocator;

include/proxy/http/Http1ServerSession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Http1ServerSession : public PoolableSession
105105
Http1ServerTransaction trans;
106106
};
107107

108-
extern ClassAllocator<Http1ServerSession, true> httpServerSessionAllocator;
108+
extern ClassAllocator<Http1ServerSession> httpServerSessionAllocator;
109109

110110
////////////////////////////////////////////
111111
// INLINE

include/proxy/http/PreWarmManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ class PreWarmSM;
138138
class PreWarmManager;
139139
class SNIConfigParams;
140140

141-
extern ClassAllocator<PreWarmSM> preWarmSMAllocator;
142-
extern PreWarmManager prewarmManager;
141+
extern PreWarmManager prewarmManager;
143142

144143
/**
145144
@class PreWarmSM
@@ -230,6 +229,8 @@ class PreWarmSM : public Continuation
230229
Event *_retry_event = nullptr;
231230
};
232231

232+
extern ClassAllocator<PreWarmSM> preWarmSMAllocator;
233+
233234
/**
234235
@class PreWarmQueue
235236
@detail

include/proxy/http2/Http2ClientSession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ class Http2ClientSession : public ProxySession, public Http2CommonSession
7979
IpEndpoint cached_local_addr;
8080
};
8181

82-
extern ClassAllocator<Http2ClientSession, true> http2ClientSessionAllocator;
82+
extern ClassAllocator<Http2ClientSession> http2ClientSessionAllocator;

include/proxy/http2/Http2Stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class Http2Stream : public ProxyTransaction
287287
Event *_write_vio_event = nullptr;
288288
};
289289

290-
extern ClassAllocator<Http2Stream, true> http2StreamAllocator;
290+
extern ClassAllocator<Http2Stream> http2StreamAllocator;
291291

292292
////////////////////////////////////////////////////
293293
// INLINE

include/tscore/Allocator.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
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
{
334335
public:
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
{
395393
public:
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

435433
private:

src/proxy/http/Http1ClientSession.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ink_mutex debug_cs_list_mutex;
5959

6060
#endif /* USE_HTTP_DEBUG_LISTS */
6161

62-
ClassAllocator<Http1ClientSession, true> http1ClientSessionAllocator("http1ClientSessionAllocator");
62+
ClassAllocator<Http1ClientSession> http1ClientSessionAllocator("http1ClientSessionAllocator");
6363

6464
namespace
6565
{

src/proxy/http/Http1ServerSession.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "proxy/http/HttpSessionManager.h"
3737
#include "proxy/http/HttpSM.h"
3838

39-
ClassAllocator<Http1ServerSession, true> httpServerSessionAllocator("httpServerSessionAllocator");
39+
ClassAllocator<Http1ServerSession> httpServerSessionAllocator("httpServerSessionAllocator");
4040

4141
namespace
4242
{

src/proxy/http2/Http2ClientSession.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "iocore/net/TLSSNISupport.h"
3030
#include "iocore/net/TLSEarlyDataSupport.h"
3131

32-
ClassAllocator<Http2ClientSession, true> http2ClientSessionAllocator("http2ClientSessionAllocator");
32+
ClassAllocator<Http2ClientSession> http2ClientSessionAllocator("http2ClientSessionAllocator");
3333

3434
namespace
3535
{

src/proxy/http2/Http2Stream.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ DbgCtl dbg_ctl_http2_stream{"http2_stream"};
4949
#define Http2StreamDebug(fmt, ...) \
5050
SsnDbg(_proxy_ssn, dbg_ctl_http2_stream, "[%" PRId64 "] [%u] " fmt, _proxy_ssn->connection_id(), this->get_id(), ##__VA_ARGS__);
5151

52-
ClassAllocator<Http2Stream, true> http2StreamAllocator("http2StreamAllocator");
52+
ClassAllocator<Http2Stream> http2StreamAllocator("http2StreamAllocator");
5353

5454
Http2Stream::Http2Stream(ProxySession *session, Http2StreamId sid, ssize_t initial_peer_rwnd, ssize_t initial_local_rwnd,
5555
bool registered_stream)

0 commit comments

Comments
 (0)