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)