From b0702678981a26371ec65dde34cb4c261e9c83c6 Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 11 May 2022 13:59:41 +0200 Subject: [PATCH] Core/Misc: Remove uses of std::aligned_storage (deprecated in future c++ standard) # Conflicts: # src/common/Threading/MPSCQueue.h # src/server/game/Server/Packets/AuctionHousePackets.cpp --- src/common/Threading/MPSCQueue.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/common/Threading/MPSCQueue.h b/src/common/Threading/MPSCQueue.h index 5f71b9dac42..a364bac09da 100644 --- a/src/common/Threading/MPSCQueue.h +++ b/src/common/Threading/MPSCQueue.h @@ -18,8 +18,10 @@ #ifndef MPSCQueue_h__ #define MPSCQueue_h__ +#include #include #include +#include namespace Trinity { @@ -92,12 +94,14 @@ private: template T::* IntrusiveLink> class MPSCQueueIntrusive { + using Atomic = std::atomic; + public: - MPSCQueueIntrusive() : _dummyPtr(reinterpret_cast(std::addressof(_dummy))), _head(_dummyPtr), _tail(_dummyPtr) + MPSCQueueIntrusive() : _dummyPtr(reinterpret_cast(_dummy.data())), _head(_dummyPtr), _tail(_dummyPtr) { - // _dummy is constructed from aligned_storage and is intentionally left uninitialized (it might not be default constructible) + // _dummy is constructed from raw byte array and is intentionally left uninitialized (it might not be default constructible) // so we init only its IntrusiveLink here - std::atomic* dummyNext = new (&(_dummyPtr->*IntrusiveLink)) std::atomic(); + Atomic* dummyNext = new (&(_dummyPtr->*IntrusiveLink)) Atomic(); dummyNext->store(nullptr, std::memory_order_relaxed); } @@ -106,6 +110,9 @@ public: T* output; while (Dequeue(output)) delete output; + + // destruct our dummy atomic + (_dummyPtr->*IntrusiveLink).~Atomic(); } void Enqueue(T* input) @@ -152,10 +159,10 @@ public: } private: - std::aligned_storage_t _dummy; + alignas(T) std::array _dummy; T* _dummyPtr; - std::atomic _head; - std::atomic _tail; + Atomic _head; + Atomic _tail; MPSCQueueIntrusive(MPSCQueueIntrusive const&) = delete; MPSCQueueIntrusive& operator=(MPSCQueueIntrusive const&) = delete;