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;