From dbd23ba63b75f53ac74fbb8b4896ab980ce2ba7c Mon Sep 17 00:00:00 2001 From: f9z Date: Fri, 20 May 2022 17:49:48 +1000 Subject: [PATCH] use allocator_traits::construct and destroy instead of placement new and dtor direct --- include/rigtorp/SPSCQueue.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/rigtorp/SPSCQueue.h b/include/rigtorp/SPSCQueue.h index 8b1c55a..2e338f2 100644 --- a/include/rigtorp/SPSCQueue.h +++ b/include/rigtorp/SPSCQueue.h @@ -114,7 +114,8 @@ template > class SPSCQueue { while (nextWriteIdx == readIdxCache_) { readIdxCache_ = readIdx_.load(std::memory_order_acquire); } - new (&slots_[writeIdx + kPadding]) T(std::forward(args)...); + std::allocator_traits::construct( + allocator_, &slots_[writeIdx + kPadding], std::forward(args)...); writeIdx_.store(nextWriteIdx, std::memory_order_release); } @@ -134,7 +135,8 @@ template > class SPSCQueue { return false; } } - new (&slots_[writeIdx + kPadding]) T(std::forward(args)...); + std::allocator_traits::construct( + allocator_, &slots_[writeIdx + kPadding], std::forward(args)...); writeIdx_.store(nextWriteIdx, std::memory_order_release); return true; } @@ -181,7 +183,8 @@ template > class SPSCQueue { "T must be nothrow destructible"); auto const readIdx = readIdx_.load(std::memory_order_relaxed); assert(writeIdx_.load(std::memory_order_acquire) != readIdx); - slots_[readIdx + kPadding].~T(); + std::allocator_traits::destroy( + allocator_, &slots_[readIdx + kPadding]); auto nextReadIdx = readIdx + 1; if (nextReadIdx == capacity_) { nextReadIdx = 0;