mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
Simplify lf_queue<> (second attempt)
It doesn't need reinterpret_cast anymore.
This commit is contained in:
parent
a4d8cab67e
commit
0c06456950
@ -311,22 +311,16 @@ 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 : public lf_queue_base
|
||||
class lf_queue final
|
||||
{
|
||||
using lf_queue_base::m_head;
|
||||
atomic_t<lf_queue_item<T>*> m_head{nullptr};
|
||||
|
||||
// Extract all elements and reverse element order (FILO to FIFO)
|
||||
lf_queue_item<T>* reverse() noexcept
|
||||
{
|
||||
if (auto* head = m_head.load() ? reinterpret_cast<lf_queue_item<T>*>(m_head.exchange(0)) : nullptr)
|
||||
if (auto* head = m_head.load() ? m_head.exchange(nullptr) : nullptr)
|
||||
{
|
||||
if (auto* prev = head->m_link)
|
||||
{
|
||||
@ -352,14 +346,14 @@ public:
|
||||
|
||||
~lf_queue()
|
||||
{
|
||||
delete reinterpret_cast<lf_queue_item<T>*>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -367,11 +361,11 @@ public:
|
||||
void push(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)...);
|
||||
auto item = new lf_queue_item<T>(_old, std::forward<Args>(args)...);
|
||||
|
||||
while (!m_head.compare_exchange(_old, reinterpret_cast<std::uint64_t>(item)))
|
||||
while (!m_head.compare_exchange(_old, item))
|
||||
{
|
||||
item->m_link = reinterpret_cast<lf_queue_item<T>*>(_old);
|
||||
item->m_link = _old;
|
||||
}
|
||||
|
||||
if (!_old)
|
||||
|
Loading…
Reference in New Issue
Block a user