From b58f8d19ab20c2b4511e3516e69a26a28d4d642c Mon Sep 17 00:00:00 2001 From: Michael M Date: Wed, 23 Aug 2017 16:45:42 -0700 Subject: [PATCH] Rename Common::FifoQueue to Common::SPSCQueue Since all queues are FIFO data structures, the name wasn't informative as to why you'd use it over a normal queue. I originally thought it had something to do with the hardware graphics FIFO. This renames it using the common acronym SPSC, which stands for single-producer single-consumer, and is most commonly used to talk about lock-free data structures, both of which this is. --- Source/Core/Common/Analytics.h | 4 ++-- Source/Core/Common/Common.vcxproj | 4 ++-- Source/Core/Common/Common.vcxproj.filters | 4 ++-- Source/Core/Common/{FifoQueue.h => SPSCQueue.h} | 10 +++++----- Source/Core/Core/CoreTiming.cpp | 4 ++-- Source/Core/Core/HW/DVD/DVDThread.cpp | 8 ++++---- Source/Core/Core/HW/WiimoteReal/WiimoteReal.h | 6 +++--- Source/Core/Core/NetPlayClient.h | 8 ++++---- Source/Core/Core/NetPlayServer.h | 4 ++-- Source/Core/DolphinWX/NetPlay/NetWindow.cpp | 2 +- Source/Core/DolphinWX/NetPlay/NetWindow.h | 4 ++-- Source/UnitTests/Common/CMakeLists.txt | 2 +- .../Common/{FifoQueueTest.cpp => SPSCQueueTest.cpp} | 10 +++++----- 13 files changed, 35 insertions(+), 35 deletions(-) rename Source/Core/Common/{FifoQueue.h => SPSCQueue.h} (91%) rename Source/UnitTests/Common/{FifoQueueTest.cpp => SPSCQueueTest.cpp} (88%) diff --git a/Source/Core/Common/Analytics.h b/Source/Core/Common/Analytics.h index de87d21f1d..f4269d0c67 100644 --- a/Source/Core/Common/Analytics.h +++ b/Source/Core/Common/Analytics.h @@ -14,9 +14,9 @@ #include "Common/CommonTypes.h" #include "Common/Event.h" -#include "Common/FifoQueue.h" #include "Common/Flag.h" #include "Common/HttpRequest.h" +#include "Common/SPSCQueue.h" // Utilities for analytics reporting in Dolphin. This reporting is designed to // provide anonymous data about how well Dolphin performs in the wild. It also @@ -157,7 +157,7 @@ protected: std::thread m_reporter_thread; Common::Event m_reporter_event; Common::Flag m_reporter_stop_request; - FifoQueue m_reports_queue; + SPSCQueue m_reports_queue; }; // Analytics backend to be used for debugging purpose, which dumps reports to diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index 71f500abf2..7c3a86c643 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -62,7 +62,6 @@ - @@ -142,6 +141,7 @@ + @@ -237,4 +237,4 @@ - \ No newline at end of file + diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index ceef3ae8e0..4dedd6eca9 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -41,7 +41,6 @@ - @@ -62,6 +61,7 @@ + @@ -336,4 +336,4 @@ - \ No newline at end of file + diff --git a/Source/Core/Common/FifoQueue.h b/Source/Core/Common/SPSCQueue.h similarity index 91% rename from Source/Core/Common/FifoQueue.h rename to Source/Core/Common/SPSCQueue.h index 1a3c5d817d..3e761d936e 100644 --- a/Source/Core/Common/FifoQueue.h +++ b/Source/Core/Common/SPSCQueue.h @@ -5,7 +5,7 @@ #pragma once // a simple lockless thread-safe, -// single reader, single writer queue +// single producer, single consumer queue #include #include @@ -16,11 +16,11 @@ namespace Common { template -class FifoQueue +class SPSCQueue { public: - FifoQueue() : m_size(0) { m_write_ptr = m_read_ptr = new ElementPtr(); } - ~FifoQueue() + SPSCQueue() : m_size(0) { m_write_ptr = m_read_ptr = new ElementPtr(); } + ~SPSCQueue() { // this will empty out the whole queue delete m_read_ptr; @@ -28,7 +28,7 @@ public: u32 Size() const { - static_assert(NeedSize, "using Size() on FifoQueue without NeedSize"); + static_assert(NeedSize, "using Size() on SPSCQueue without NeedSize"); return m_size.load(); } diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp index 3da6bc12d3..62e3ce31f0 100644 --- a/Source/Core/Core/CoreTiming.cpp +++ b/Source/Core/Core/CoreTiming.cpp @@ -13,8 +13,8 @@ #include "Common/Assert.h" #include "Common/ChunkFile.h" -#include "Common/FifoQueue.h" #include "Common/Logging/Log.h" +#include "Common/SPSCQueue.h" #include "Common/StringUtil.h" #include "Common/Thread.h" @@ -63,7 +63,7 @@ static std::unordered_map s_event_types; static std::vector s_event_queue; static u64 s_event_fifo_id; static std::mutex s_ts_write_lock; -static Common::FifoQueue s_ts_queue; +static Common::SPSCQueue s_ts_queue; static float s_last_OC_factor; static constexpr int MAX_SLICE_LENGTH = 20000; diff --git a/Source/Core/Core/HW/DVD/DVDThread.cpp b/Source/Core/Core/HW/DVD/DVDThread.cpp index 33fdc279c4..57be86c73b 100644 --- a/Source/Core/Core/HW/DVD/DVDThread.cpp +++ b/Source/Core/Core/HW/DVD/DVDThread.cpp @@ -16,10 +16,10 @@ #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" #include "Common/Event.h" -#include "Common/FifoQueue.h" #include "Common/Flag.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" +#include "Common/SPSCQueue.h" #include "Common/Thread.h" #include "Common/Timer.h" @@ -83,8 +83,8 @@ static Common::Event s_request_queue_expanded; // Is set by CPU thread static Common::Event s_result_queue_expanded; // Is set by DVD thread static Common::Flag s_dvd_thread_exiting(false); // Is set by CPU thread -static Common::FifoQueue s_request_queue; -static Common::FifoQueue s_result_queue; +static Common::SPSCQueue s_request_queue; +static Common::SPSCQueue s_result_queue; static std::map s_result_map; static std::unique_ptr s_disc; @@ -140,7 +140,7 @@ void DoState(PointerWrap& p) WaitUntilIdle(); // Move all results from s_result_queue to s_result_map because - // PointerWrap::Do supports std::map but not Common::FifoQueue. + // PointerWrap::Do supports std::map but not Common::SPSCQueue. // This won't affect the behavior of FinishRead. ReadResult result; while (s_result_queue.Pop(result)) diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h index 98754a8ae3..d1b4c65086 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h @@ -12,8 +12,8 @@ #include "Common/Common.h" #include "Common/Event.h" -#include "Common/FifoQueue.h" #include "Common/Flag.h" +#include "Common/SPSCQueue.h" #include "Core/HW/Wiimote.h" #include "Core/HW/WiimoteCommon/WiimoteConstants.h" #include "Core/HW/WiimoteCommon/WiimoteHid.h" @@ -112,8 +112,8 @@ private: // Triggered when the thread has finished ConnectInternal. Common::Event m_thread_ready_event; - Common::FifoQueue m_read_reports; - Common::FifoQueue m_write_reports; + Common::SPSCQueue m_read_reports; + Common::SPSCQueue m_write_reports; }; class WiimoteScannerBackend diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 978cec9cb4..36134d5eb8 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -13,7 +13,7 @@ #include #include "Common/CommonTypes.h" #include "Common/Event.h" -#include "Common/FifoQueue.h" +#include "Common/SPSCQueue.h" #include "Common/TraversalClient.h" #include "Core/NetPlayProto.h" #include "InputCommon/GCPadStatus.h" @@ -109,10 +109,10 @@ protected: std::recursive_mutex async_queue_write; } m_crit; - Common::FifoQueue m_async_queue; + Common::SPSCQueue m_async_queue; - std::array, 4> m_pad_buffer; - std::array, 4> m_wiimote_buffer; + std::array, 4> m_pad_buffer; + std::array, 4> m_wiimote_buffer; NetPlayUI* m_dialog = nullptr; diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index 84bb2fba6e..e67aaf1266 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -12,7 +12,7 @@ #include #include #include -#include "Common/FifoQueue.h" +#include "Common/SPSCQueue.h" #include "Common/Timer.h" #include "Common/TraversalClient.h" #include "Core/NetPlayProto.h" @@ -114,7 +114,7 @@ private: std::string m_selected_game; std::thread m_thread; - Common::FifoQueue m_async_queue; + Common::SPSCQueue m_async_queue; ENetHost* m_server = nullptr; TraversalClient* m_traversal_client = nullptr; diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index 5aaf6ecbf7..ec6b6bba0b 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -33,9 +33,9 @@ #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" #include "Common/Config/Config.h" -#include "Common/FifoQueue.h" #include "Common/FileUtil.h" #include "Common/MsgHandler.h" +#include "Common/SPSCQueue.h" #include "Common/StringUtil.h" #include "Core/Config/SYSCONFSettings.h" diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.h b/Source/Core/DolphinWX/NetPlay/NetWindow.h index e3ccbf952f..599ffa4fac 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.h +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.h @@ -9,7 +9,7 @@ #include #include "Common/CommonTypes.h" -#include "Common/FifoQueue.h" +#include "Common/SPSCQueue.h" #include "Core/NetPlayClient.h" #include "Core/NetPlayProto.h" #include "Core/NetPlayServer.h" @@ -161,7 +161,7 @@ private: std::string m_desync_player; std::vector m_playerids; - Common::FifoQueue m_chat_msgs; + Common::SPSCQueue m_chat_msgs; const GameListCtrl* const m_game_list; diff --git a/Source/UnitTests/Common/CMakeLists.txt b/Source/UnitTests/Common/CMakeLists.txt index 8b0eed1abf..6736348c8b 100644 --- a/Source/UnitTests/Common/CMakeLists.txt +++ b/Source/UnitTests/Common/CMakeLists.txt @@ -5,11 +5,11 @@ add_dolphin_test(BlockingLoopTest BlockingLoopTest.cpp) add_dolphin_test(BusyLoopTest BusyLoopTest.cpp) add_dolphin_test(CommonFuncsTest CommonFuncsTest.cpp) add_dolphin_test(EventTest EventTest.cpp) -add_dolphin_test(FifoQueueTest FifoQueueTest.cpp) add_dolphin_test(FixedSizeQueueTest FixedSizeQueueTest.cpp) add_dolphin_test(FlagTest FlagTest.cpp) add_dolphin_test(MathUtilTest MathUtilTest.cpp) add_dolphin_test(NandPathsTest NandPathsTest.cpp) +add_dolphin_test(SPSCQueueTest SPSCQueueTest.cpp) add_dolphin_test(StringUtilTest StringUtilTest.cpp) add_dolphin_test(SwapTest SwapTest.cpp) add_dolphin_test(x64EmitterTest x64EmitterTest.cpp) diff --git a/Source/UnitTests/Common/FifoQueueTest.cpp b/Source/UnitTests/Common/SPSCQueueTest.cpp similarity index 88% rename from Source/UnitTests/Common/FifoQueueTest.cpp rename to Source/UnitTests/Common/SPSCQueueTest.cpp index e4f3c913c1..0a4fbfcc1c 100644 --- a/Source/UnitTests/Common/FifoQueueTest.cpp +++ b/Source/UnitTests/Common/SPSCQueueTest.cpp @@ -5,11 +5,11 @@ #include #include -#include "Common/FifoQueue.h" +#include "Common/SPSCQueue.h" -TEST(FifoQueue, Simple) +TEST(SPSCQueue, Simple) { - Common::FifoQueue q; + Common::SPSCQueue q; EXPECT_EQ(0u, q.Size()); EXPECT_TRUE(q.Empty()); @@ -43,9 +43,9 @@ TEST(FifoQueue, Simple) EXPECT_TRUE(q.Empty()); } -TEST(FifoQueue, MultiThreaded) +TEST(SPSCQueue, MultiThreaded) { - Common::FifoQueue q; + Common::SPSCQueue q; auto inserter = [&q]() { for (u32 i = 0; i < 100000; ++i)