From 27674c2dc96a372986956d6fd93528022f41d49a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 26 Oct 2019 17:41:29 +1000 Subject: [PATCH] FIFOQueue: Support copying from another queue (pop -> push) --- src/common/fifo_queue.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/common/fifo_queue.h b/src/common/fifo_queue.h index f873c5816..2e330a859 100644 --- a/src/common/fifo_queue.h +++ b/src/common/fifo_queue.h @@ -1,6 +1,7 @@ #pragma once #include "YBaseLib/Assert.h" #include "types.h" +#include #include #include @@ -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(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 + void PushFromQueue(FIFOQueue* other_queue) + { + while (!other_queue->IsEmpty() && !IsFull()) + { + T& dest = PushAndGetReference(); + dest = std::move(other_queue->Pop()); + } + } + protected: FIFOQueue() = default;