From 015cee5f272217010f7e59b96ddde36debb07ea1 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 20 Aug 2020 16:06:15 +0200 Subject: Core/Networking: Initialize MPSCQueueIntrusive dummy node without undefined behavior (cherry picked from commit e1289805fc04e75f9e7cba078cbc826ce60f037a) --- src/common/Threading/MPSCQueue.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/common/Threading') diff --git a/src/common/Threading/MPSCQueue.h b/src/common/Threading/MPSCQueue.h index ac245e1b332..5f71b9dac42 100644 --- a/src/common/Threading/MPSCQueue.h +++ b/src/common/Threading/MPSCQueue.h @@ -95,10 +95,10 @@ class MPSCQueueIntrusive public: MPSCQueueIntrusive() : _dummyPtr(reinterpret_cast(std::addressof(_dummy))), _head(_dummyPtr), _tail(_dummyPtr) { - T* front = _head.load(std::memory_order_relaxed); - (front->*IntrusiveLink).store(nullptr, std::memory_order_relaxed); - // _dummy is constructed from aligned_storage and is left uninitialized so we init only its Next here - (_dummyPtr->*IntrusiveLink).store(nullptr, std::memory_order_relaxed); + // _dummy is constructed from aligned_storage 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(); + dummyNext->store(nullptr, std::memory_order_relaxed); } ~MPSCQueueIntrusive() -- cgit v1.2.3