Skip to content

Commit 5f9211c

Browse files
committed
restore destruct flag but invert default
1 parent 1cb5fad commit 5f9211c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+123
-119
lines changed

include/iocore/eventsystem/Event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class Event : public Action
280280
//
281281
// Event Allocator
282282
//
283-
extern ClassAllocator<Event> eventAllocator;
283+
extern ClassAllocator<Event, false> eventAllocator;
284284

285285
#define EVENT_ALLOC(_a, _t) THREAD_ALLOC(_a, _t)
286286
#define EVENT_FREE(_p, _a, _t) \

include/iocore/eventsystem/IOBuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class IOBufferData : public RefCountObj
251251
IOBufferData &operator=(const IOBufferData &) = delete;
252252
};
253253

254-
extern ClassAllocator<IOBufferData> ioDataAllocator;
254+
extern ClassAllocator<IOBufferData, false> ioDataAllocator;
255255

256256
/**
257257
A linkable portion of IOBufferData. IOBufferBlock is a chainable
@@ -494,7 +494,7 @@ class IOBufferBlock : public RefCountObj
494494
IOBufferBlock &operator=(const IOBufferBlock &) = delete;
495495
};
496496

497-
extern ClassAllocator<IOBufferBlock> ioBlockAllocator;
497+
extern ClassAllocator<IOBufferBlock, false> ioBlockAllocator;
498498

499499
/** A class for holding a chain of IO buffer blocks.
500500
This class is intended to be used as a member variable for other classes that

include/iocore/eventsystem/Lock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class ProxyMutex : public RefCountObj
247247
};
248248

249249
// The ClassAllocator for ProxyMutexes
250-
extern ClassAllocator<ProxyMutex> mutexAllocator;
250+
extern ClassAllocator<ProxyMutex, false> mutexAllocator;
251251

252252
inline bool
253253
Mutex_trylock(

include/iocore/utils/OneWayMultiTunnel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ struct OneWayMultiTunnel : public OneWayTunnel {
131131
VIO *vioTargets[ONE_WAY_MULTI_TUNNEL_LIMIT];
132132
};
133133

134-
extern ClassAllocator<OneWayMultiTunnel> OneWayMultiTunnelAllocator;
134+
extern ClassAllocator<OneWayMultiTunnel, false> OneWayMultiTunnelAllocator;

include/proxy/http/PreWarmManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class PreWarmSM : public Continuation
229229
Event *_retry_event = nullptr;
230230
};
231231

232-
extern ClassAllocator<PreWarmSM> preWarmSMAllocator;
232+
extern ClassAllocator<PreWarmSM, false> preWarmSMAllocator;
233233

234234
/**
235235
@class PreWarmQueue

include/proxy/http2/Http2ServerSession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ class Http2ServerSession : public PoolableSession, public Http2CommonSession
103103
bool in_session_table = false;
104104
};
105105

106-
extern ClassAllocator<Http2ServerSession> http2ServerSessionAllocator;
106+
extern ClassAllocator<Http2ServerSession, false> http2ServerSessionAllocator;

include/proxy/http3/Http3Frame.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ using Http3FrameUPtr = std::unique_ptr<Http3Frame, Http3FrameDeleterFunc>
175175
using Http3DataFrameUPtr = std::unique_ptr<Http3DataFrame, Http3FrameDeleterFunc>;
176176
using Http3HeadersFrameUPtr = std::unique_ptr<Http3HeadersFrame, Http3FrameDeleterFunc>;
177177

178-
extern ClassAllocator<Http3Frame> http3FrameAllocator;
179-
extern ClassAllocator<Http3DataFrame> http3DataFrameAllocator;
180-
extern ClassAllocator<Http3HeadersFrame> http3HeadersFrameAllocator;
181-
extern ClassAllocator<Http3SettingsFrame> http3SettingsFrameAllocator;
178+
extern ClassAllocator<Http3Frame, false> http3FrameAllocator;
179+
extern ClassAllocator<Http3DataFrame, false> http3DataFrameAllocator;
180+
extern ClassAllocator<Http3HeadersFrame, false> http3HeadersFrameAllocator;
181+
extern ClassAllocator<Http3SettingsFrame, false> http3SettingsFrameAllocator;
182182

183183
class Http3FrameDeleter
184184
{

include/tscore/Allocator.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,12 @@ using Allocator = FreelistAllocator;
330330
Allocator for Class objects.
331331
332332
*/
333-
template <std::destructible C, typename BaseAllocator = Allocator> class ClassAllocator : public BaseAllocator
333+
template <std::destructible C, bool Destruct_on_free_ = true, typename BaseAllocator = Allocator>
334+
class ClassAllocator : public BaseAllocator
334335
{
335336
public:
336-
using Value_type = C;
337+
using Value_type = C;
338+
static bool const Destruct_on_free = Destruct_on_free_;
337339

338340
/** Allocates objects of the templated type. Arguments are forwarded to the constructor for the object. */
339341
template <typename... Args>
@@ -380,19 +382,21 @@ template <std::destructible C, typename BaseAllocator = Allocator> class ClassAl
380382
void
381383
destroy_if_enabled(C *ptr)
382384
{
383-
std::destroy_at(ptr);
385+
if constexpr (Destruct_on_free) {
386+
std::destroy_at(ptr);
387+
}
384388
}
385389

386390
// Ensure that C is big enough to hold a void pointer (when it's stored in the free list as raw memory).
387391
//
388392
static_assert(sizeof(C) >= sizeof(void *), "Can not allocate instances of this class using ClassAllocator");
389393
};
390394

391-
template <class C> class TrackerClassAllocator : public ClassAllocator<C>
395+
template <class C, bool Destruct_on_free = true> class TrackerClassAllocator : public ClassAllocator<C, Destruct_on_free>
392396
{
393397
public:
394398
TrackerClassAllocator(const char *name, unsigned int chunk_size = 128, unsigned int alignment = 16)
395-
: ClassAllocator<C>(name, chunk_size, alignment), allocations(0), trackerLock(PTHREAD_MUTEX_INITIALIZER)
399+
: ClassAllocator<C, Destruct_on_free>(name, chunk_size, alignment), allocations(0), trackerLock(PTHREAD_MUTEX_INITIALIZER)
396400
{
397401
}
398402

@@ -401,7 +405,7 @@ template <class C> class TrackerClassAllocator : public ClassAllocator<C>
401405
{
402406
void *callstack[3];
403407
int frames = backtrace(callstack, 3);
404-
C *ptr = ClassAllocator<C>::alloc();
408+
C *ptr = ClassAllocator<C, Destruct_on_free>::alloc();
405409

406410
const void *symbol = nullptr;
407411
if (frames == 3 && callstack[2] != nullptr) {
@@ -427,7 +431,7 @@ template <class C> class TrackerClassAllocator : public ClassAllocator<C>
427431
reverse_lookup.erase(it);
428432
}
429433
ink_mutex_release(&trackerLock);
430-
ClassAllocator<C>::free(ptr);
434+
ClassAllocator<C, Destruct_on_free>::free(ptr);
431435
}
432436

433437
private:

plugins/experimental/memcache/tsmemcache.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define REALTIME_MAXDELTA 60 * 60 * 24 * 30
3838
#define STRCMP_REST(_c, _s, _e) (((_e) - (_s)) < (int)sizeof(_c) || STRCMP(_s, _c) || !isspace((_s)[sizeof(_c) - 1]))
3939

40-
ClassAllocator<MC> theMCAllocator("MC");
40+
ClassAllocator<MC, false> theMCAllocator("MC");
4141

4242
static time_t base_day_time;
4343

plugins/header_rewrite/matcher_tests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ TSHttpTxnServerRespGet(TSHttpTxn, TSMBuffer *, TSMLoc *)
8383
return TS_SUCCESS;
8484
}
8585

86-
ClassAllocator<ProxyMutex> mutexAllocator("mutexAllocator");
86+
ClassAllocator<ProxyMutex, false> mutexAllocator("mutexAllocator");
8787

8888
TEST_CASE("Matcher", "[plugins][header_rewrite]")
8989
{

0 commit comments

Comments
 (0)