1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Revert "Simplify lf_queue<>"

This reverts commit 050e5b4aec.
This commit is contained in:
Nekotekina 2019-10-23 21:53:55 +03:00
parent d0ea71289e
commit 6867fc5f06

View File

@ -311,16 +311,22 @@ public:
}
};
class lf_queue_base
{
protected:
atomic_t<std::uintptr_t> m_head = 0;
};
// Linked list-based multi-producer queue (the consumer drains the whole queue at once)
template <typename T>
class lf_queue final
class lf_queue : public lf_queue_base
{
atomic_t<lf_queue_item<T>*> m_head;
using lf_queue_base::m_head;
// Extract all elements and reverse element order (FILO to FIFO)
lf_queue_item<T>* reverse() noexcept
{
if (auto* head = m_head.load() ? m_head.exchange(nullptr) : nullptr)
if (auto* head = m_head.load() ? reinterpret_cast<lf_queue_item<T>*>(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<lf_queue_item<T>*>(m_head.load());
}
void wait() noexcept
{
if (m_head == nullptr)
if (m_head == 0)
{
m_head.wait(nullptr);
m_head.wait(0);
}
}
template <typename... Args>
void push(Args&&... args)
{
auto _old = m_head.load();
auto item = new lf_queue_item<T>(_old, std::forward<Args>(args)...);
auto _old = m_head.load();
auto* item = new lf_queue_item<T>(reinterpret_cast<lf_queue_item<T>*>(_old), std::forward<Args>(args)...);
while (!m_head.compare_exchange(_old, item))
while (!m_head.compare_exchange(_old, reinterpret_cast<std::uint64_t>(item)))
{
item->m_link = _old;
item->m_link = reinterpret_cast<lf_queue_item<T>*>(_old);
}
if (!_old)