From 17d24c62d8808bd27994886aa753924538f7bcd6 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 12 Nov 2026 13:53:24 -0600 Subject: Common/SPSCQueue: Hold an array of values in each linked node to make SPSCQueue of u8 practical. --- Source/UnitTests/Common/SPSCQueueTest.cpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'Source/UnitTests/Common/SPSCQueueTest.cpp') diff --git a/Source/UnitTests/Common/SPSCQueueTest.cpp b/Source/UnitTests/Common/SPSCQueueTest.cpp index ddc57c8d1a..751d43809b 100644 --- a/Source/UnitTests/Common/SPSCQueueTest.cpp +++ b/Source/UnitTests/Common/SPSCQueueTest.cpp @@ -89,3 +89,43 @@ TEST(SPSCQueue, MultiThreaded) queue_ptr.reset(); EXPECT_EQ(sptr.use_count(), 1); } + +TEST(SPSCQueue, MoveOnlyElement) +{ + Common::SPSCQueue> q; + q.Push(std::make_unique(42)); + + EXPECT_EQ(*std::as_const(q).Front(), 42); + + auto x2 = std::move(q.Front()); + EXPECT_EQ(*x2, 42); + q.Pop(); +} + +TEST(SPSCQueue, LargeElement) +{ + Common::SPSCQueue> q; + q.Emplace(); + q.Pop(); +} + +TEST(SPSCQueue, SmallElement) +{ + Common::WaitableSPSCQueue q; + + constexpr u32 reps = 100000; + + std::jthread pusher{[&] { + for (u32 i = 0; i != reps; ++i) + q.Push(u8(i)); + }}; + + std::jthread popper{[&] { + for (u32 i = 0; i != reps; ++i) + { + q.WaitForData(); + EXPECT_EQ(u8(i), q.Front()); + q.Pop(); + } + }}; +} -- cgit v1.2.3