diff --git a/Utilities/lockless.h b/Utilities/lockless.h index 62b9a08bdd..98b8e891af 100644 --- a/Utilities/lockless.h +++ b/Utilities/lockless.h @@ -311,22 +311,16 @@ 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 : public lf_queue_base +class lf_queue final { - using lf_queue_base::m_head; + atomic_t*> m_head; // Extract all elements and reverse element order (FILO to FIFO) lf_queue_item* reverse() noexcept { - if (auto* head = m_head.load() ? reinterpret_cast*>(m_head.exchange(0)) : nullptr) + if (auto* head = m_head.load() ? m_head.exchange(nullptr) : nullptr) { if (auto* prev = head->m_link) { @@ -352,26 +346,26 @@ public: ~lf_queue() { - delete reinterpret_cast*>(m_head.load()); + delete m_head.load(); } void wait() noexcept { - if (m_head == 0) + if (m_head == nullptr) { - m_head.wait(0); + m_head.wait(nullptr); } } template void push(Args&&... args) { - auto _old = m_head.load(); - auto* item = new lf_queue_item(reinterpret_cast*>(_old), std::forward(args)...); + auto _old = m_head.load(); + auto item = new lf_queue_item(_old, std::forward(args)...); - while (!m_head.compare_exchange(_old, reinterpret_cast(item))) + while (!m_head.compare_exchange(_old, item)) { - item->m_link = reinterpret_cast*>(_old); + item->m_link = _old; } if (!_old)