mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 22:05:38 +00:00
FIFOQueue: Support copying from another queue (pop -> push)
This commit is contained in:
parent
3ded9d46c1
commit
27674c2dc9
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "YBaseLib/Assert.h"
|
||||
#include "types.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
|
||||
|
@ -17,6 +18,8 @@ public:
|
|||
constexpr u32 GetCapacity() const { return CAPACITY; }
|
||||
u32 GetSize() const { return m_size; }
|
||||
u32 GetSpace() const { return CAPACITY - m_size; }
|
||||
u32 GetContiguousSpace() const { return (m_tail >= m_head) ? (CAPACITY - m_tail) : (m_head - m_tail); }
|
||||
u32 GetContiguousSize() const { return std::min<u32>(CAPACITY - m_head, m_size); }
|
||||
bool IsEmpty() const { return m_size == 0; }
|
||||
bool IsFull() const { return m_size == CAPACITY; }
|
||||
|
||||
|
@ -131,6 +134,16 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
template<u32 CAPACITY>
|
||||
void PushFromQueue(FIFOQueue<T, CAPACITY>* other_queue)
|
||||
{
|
||||
while (!other_queue->IsEmpty() && !IsFull())
|
||||
{
|
||||
T& dest = PushAndGetReference();
|
||||
dest = std::move(other_queue->Pop());
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
FIFOQueue() = default;
|
||||
|
||||
|
|
Loading…
Reference in a new issue