From 23854f84024c292164ce49b3fefee2a9b4fe0831 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Tue, 3 May 2022 18:34:31 +0200 Subject: [PATCH 1/3] refactor: make MainSignalsInstance() a class and use Doxygen documentation for it, per our developer notes. Context: MainSignalsInstance was created in 3a19fed9db5 and originally was a struct collection of boost::signals methods moved to validationinterface.cpp, in order to no longer need to include boost/signals in validationinterface.h. MainSignalsInstance then evolved in d6815a23131 to remove boost/signals2 and became class-like. [C.8: Use class rather than struct if any member is non-public](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-class) [C.2: Use class if the class has an invariant; use struct if the data members can vary independently](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c2-use-class-if-the-class-has-an-invariant-use-struct-if-the-data-members-can-vary-independently) A class also has the advantage of default private access, as opposed to public for a struct. --- src/validationinterface.cpp | 18 ++++++++++-------- src/validationinterface.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index edc4633c012..0cb48a19cb7 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -16,14 +16,16 @@ #include #include -//! The MainSignalsInstance manages a list of shared_ptr -//! callbacks. -//! -//! A std::unordered_map is used to track what callbacks are currently -//! registered, and a std::list is to used to store the callbacks that are -//! currently registered as well as any callbacks that are just unregistered -//! and about to be deleted when they are done executing. -struct MainSignalsInstance { +/** + * MainSignalsInstance manages a list of shared_ptr callbacks. + * + * A std::unordered_map is used to track what callbacks are currently + * registered, and a std::list is used to store the callbacks that are + * currently registered as well as any callbacks that are just unregistered + * and about to be deleted when they are done executing. + */ +class MainSignalsInstance +{ private: Mutex m_mutex; //! List entries consist of a callback pointer and reference count. The diff --git a/src/validationinterface.h b/src/validationinterface.h index ac62f8b467d..6b38655ff1c 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -177,7 +177,7 @@ protected: friend class ValidationInterfaceTest; }; -struct MainSignalsInstance; +class MainSignalsInstance; class CMainSignals { private: std::unique_ptr m_internals; From 2aaec2352d14753e1f2d4bf4b11bbe6ad42edf5c Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Mon, 9 May 2022 15:15:05 +0200 Subject: [PATCH 2/3] refactor: remove unused forward declarations in validationinterface.h --- src/validationinterface.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/validationinterface.h b/src/validationinterface.h index 6b38655ff1c..c825ba25d65 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -17,9 +17,7 @@ class BlockValidationState; class CBlock; class CBlockIndex; struct CBlockLocator; -class CConnman; class CValidationInterface; -class uint256; class CScheduler; enum class MemPoolRemovalReason; From ca1ac1f0e0fbabbe97666aca94024afb8104da06 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Mon, 9 May 2022 18:12:35 +0200 Subject: [PATCH 3/3] scripted-diff: Rename MainSignalsInstance() class to MainSignalsImpl() ``` -BEGIN VERIFY SCRIPT- s() { git grep -l "$1" src test doc | xargs sed -i "s/$1/$2/g"; } s 'MainSignalsInstance' 'MainSignalsImpl' -END VERIFY SCRIPT- --- src/validationinterface.cpp | 8 ++++---- src/validationinterface.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 0cb48a19cb7..7991222496b 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -17,14 +17,14 @@ #include /** - * MainSignalsInstance manages a list of shared_ptr callbacks. + * MainSignalsImpl manages a list of shared_ptr callbacks. * * A std::unordered_map is used to track what callbacks are currently * registered, and a std::list is used to store the callbacks that are * currently registered as well as any callbacks that are just unregistered * and about to be deleted when they are done executing. */ -class MainSignalsInstance +class MainSignalsImpl { private: Mutex m_mutex; @@ -42,7 +42,7 @@ public: // our own queue here :( SingleThreadedSchedulerClient m_schedulerClient; - explicit MainSignalsInstance(CScheduler& scheduler LIFETIMEBOUND) : m_schedulerClient(scheduler) {} + explicit MainSignalsImpl(CScheduler& scheduler LIFETIMEBOUND) : m_schedulerClient(scheduler) {} void Register(std::shared_ptr callbacks) { @@ -94,7 +94,7 @@ static CMainSignals g_signals; void CMainSignals::RegisterBackgroundSignalScheduler(CScheduler& scheduler) { assert(!m_internals); - m_internals = std::make_unique(scheduler); + m_internals = std::make_unique(scheduler); } void CMainSignals::UnregisterBackgroundSignalScheduler() diff --git a/src/validationinterface.h b/src/validationinterface.h index c825ba25d65..a929a3d56bf 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -175,10 +175,10 @@ protected: friend class ValidationInterfaceTest; }; -class MainSignalsInstance; +class MainSignalsImpl; class CMainSignals { private: - std::unique_ptr m_internals; + std::unique_ptr m_internals; friend void ::RegisterSharedValidationInterface(std::shared_ptr); friend void ::UnregisterValidationInterface(CValidationInterface*);