aboutsummaryrefslogtreecommitdiff
path: root/src/common/Threading/MPSCQueue.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-08-20 16:06:15 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-04 00:27:11 +0100
commit015cee5f272217010f7e59b96ddde36debb07ea1 (patch)
tree191392745180e4d1a44c188d4324a32a6cb88abf /src/common/Threading/MPSCQueue.h
parent0a1acb9c0506b3ede101c134d181700c8f271d6c (diff)
Core/Networking: Initialize MPSCQueueIntrusive dummy node without undefined behavior
(cherry picked from commit e1289805fc04e75f9e7cba078cbc826ce60f037a)
Diffstat (limited to 'src/common/Threading/MPSCQueue.h')
-rw-r--r--src/common/Threading/MPSCQueue.h8
1 files changed, 4 insertions, 4 deletions
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<T*>(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<T*>* dummyNext = new (&(_dummyPtr->*IntrusiveLink)) std::atomic<T*>();
+ dummyNext->store(nullptr, std::memory_order_relaxed);
}
~MPSCQueueIntrusive()