masaori335 commented on a change in pull request #6241:
URL: https://github.com/apache/trafficserver/pull/6241#discussion_r585242214
##########
File path: iocore/eventsystem/I_ProxyAllocator.h
##########
@@ -45,84 +48,49 @@ struct ProxyAllocator {
ProxyAllocator() {}
};
-template <class C>
-inline C *
-thread_alloc(ClassAllocator<C> &a, ProxyAllocator &l)
+template <class CAlloc, typename... Args>
+typename CAlloc::Value_type *
+thread_alloc(CAlloc &a, ProxyAllocator &l, Args &&... args)
{
if (!cmd_disable_pfreelist && l.freelist) {
- C *v = (C *)l.freelist;
- l.freelist = *(C **)l.freelist;
+ void *v = l.freelist;
+ l.freelist = *reinterpret_cast<void **>(l.freelist);
--(l.allocated);
- *(void **)v = *(void **)&a.proto.typeObject;
- return v;
+ ::new (v) typename CAlloc::Value_type(std::forward<Args>(args)...);
+ return static_cast<typename CAlloc::Value_type *>(v);
}
- return a.alloc();
+ return a.alloc(std::forward<Args>(args)...);
}
-template <class C>
-inline C *
-thread_alloc_init(ClassAllocator<C> &a, ProxyAllocator &l)
-{
- if (!cmd_disable_pfreelist && l.freelist) {
- C *v = (C *)l.freelist;
- l.freelist = *(C **)l.freelist;
- --(l.allocated);
- memcpy((void *)v, (void *)&a.proto.typeObject, sizeof(C));
- return v;
- }
- return a.alloc();
-}
+void *thread_alloc(Allocator &a, ProxyAllocator &l);
+void thread_freeup(Allocator &a, ProxyAllocator &l);
-template <class C>
-inline void
-thread_free(ClassAllocator<C> &a, C *p)
-{
- a.free(p);
-}
+#if 1
-static inline void
-thread_free(Allocator &a, void *p)
-{
- a.free_void(p);
-}
-
-template <class C>
-inline void
-thread_freeup(ClassAllocator<C> &a, ProxyAllocator &l)
-{
- C *head = (C *)l.freelist;
- C *tail = (C *)l.freelist;
- size_t count = 0;
- while (l.freelist && l.allocated > thread_freelist_low_watermark) {
- tail = (C *)l.freelist;
- l.freelist = *(C **)l.freelist;
- --(l.allocated);
- ++count;
- }
+// Potentially empty varaiable arguments -- non-standard GCC way
+//
+#define THREAD_ALLOC(_a, _t, ...) thread_alloc(::_a, _t->_a, ##__VA_ARGS__)
+#define THREAD_ALLOC_INIT(_a, _t, ...) thread_alloc(::_a, _t->_a,
##__VA_ARGS__)
- if (unlikely(count == 1)) {
- a.free(tail);
- } else if (count > 0) {
- a.free_bulk(head, tail, count);
- }
+#else
- ink_assert(l.allocated >= thread_freelist_low_watermark);
-}
+// Potentially empty varaiable arguments -- Standard way
+//
+#define THREAD_ALLOC(_a, _t, ...) thread_alloc(::_a, _t->_a __VA_OPT__(, )
__VA_ARGS__)
Review comment:
note: We can't go with this "Standard" way until C++20. (`__VA_OPT__` is
introduced by C++20)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]