diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2026-11-23 22:56:09 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 22:56:09 -0600 |
| commit | 0318069674bbd7971f0db434fe1f7bd9f1c5750e (patch) | |
| tree | b3661af6d86c493cd9a6d343c1310b50ea808829 /Source/UnitTests | |
| parent | e5618dd217c32e27c4d46bab1fc59986d8458e2e (diff) | |
| parent | 17d24c62d8808bd27994886aa753924538f7bcd6 (diff) | |
Merge pull request #15018 from jordan-woyak/spsc-queue-node-array
Common/SPSCQueue: Hold an array of values in each linked node to make SPSCQueue of u8 practical.
Diffstat (limited to 'Source/UnitTests')
| -rw-r--r-- | Source/UnitTests/Common/SPSCQueueTest.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
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<std::unique_ptr<int>> q; + q.Push(std::make_unique<int>(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<std::array<u32, 4096>> q; + q.Emplace(); + q.Pop(); +} + +TEST(SPSCQueue, SmallElement) +{ + Common::WaitableSPSCQueue<u8> 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(); + } + }}; +} |
