From 6867fc5f06c59f01e743930aa69f36c5850fc5e3 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 23 Oct 2019 21:53:55 +0300 Subject: [PATCH] Revert "Simplify lf_queue<>" This reverts commit 050e5b4aec533da248478bd5bf7abd0784e5d805. --- Utilities/lockless.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Utilities/lockless.h b/Utilities/lockless.h index 98b8e891af..62b9a08bdd 100644 --- a/Utilities/lockless.h +++ b/Utilities/lockless.h @@ -311,16 +311,22 @@ public: } }; +class lf_queue_base +{ +protected: + atomic_t m_head = 0; +}; + // Linked list-based multi-producer queue (the consumer drains the whole queue at once) template -class lf_queue final +class lf_queue : public lf_queue_base { - atomic_t*> m_head; + using lf_queue_base::m_head; // Extract all elements and reverse element order (FILO to FIFO) lf_queue_item* reverse() noexcept { - if (auto* head = m_head.load() ? m_head.exchange(nullptr) : nullptr) + if (auto* head = m_head.load() ? reinterpret_cast*>(m_head.exchange(0)) : nullptr) { if (auto* prev = head->m_link) { @@ -346,26 +352,26 @@ public: ~lf_queue() { - delete m_head.load(); + delete reinterpret_cast*>(m_head.load()); } void wait() noexcept { - if (m_head == nullptr) + if (m_head == 0) { - m_head.wait(nullptr); + m_head.wait(0); } } template void push(Args&&... args) { - auto _old = m_head.load(); - auto item = new lf_queue_item(_old, std::forward(args)...); + auto _old = m_head.load(); + auto* item = new lf_queue_item(reinterpret_cast*>(_old), std::forward(args)...); - while (!m_head.compare_exchange(_old, item)) + while (!m_head.compare_exchange(_old, reinterpret_cast(item))) { - item->m_link = _old; + item->m_link = reinterpret_cast*>(_old); } if (!_old)