File tree Expand file tree Collapse file tree 5 files changed +31
-0
lines changed
Expand file tree Collapse file tree 5 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -301,6 +301,7 @@ void PrepareShutdown()
301301
302302 // Disconnect all slots
303303 UnregisterAllValidationInterfaces ();
304+ GetMainSignals ().UnregisterBackgroundSignalScheduler ();
304305
305306#ifndef WIN32
306307 try {
@@ -1243,6 +1244,8 @@ bool AppInitMain()
12431244 CScheduler::Function serviceLoop = std::bind (&CScheduler::serviceQueue, &scheduler);
12441245 threadGroup.create_thread (std::bind (&TraceThread<CScheduler::Function>, " scheduler" , serviceLoop));
12451246
1247+ GetMainSignals ().RegisterBackgroundSignalScheduler (scheduler);
1248+
12461249 // Initialize Sapling circuit parameters
12471250 LoadSaplingParams ();
12481251
Original file line number Diff line number Diff line change @@ -53,6 +53,12 @@ TestingSetup::TestingSetup()
5353 pathTemp = GetTempPath () / strprintf (" test_pivx_%lu_%i" , (unsigned long )GetTime (), (int )(InsecureRandRange (100000 )));
5454 fs::create_directories (pathTemp);
5555 gArgs .ForceSetArg (" -datadir" , pathTemp.string ());
56+
57+ // Note that because we don't bother running a scheduler thread here,
58+ // callbacks via CValidationInterface are unreliable, but that's OK,
59+ // our unit tests aren't testing multiple parts of the code at once.
60+ GetMainSignals ().RegisterBackgroundSignalScheduler (scheduler);
61+
5662 // Ideally we'd move all the RPC tests to the functional testing framework
5763 // instead of unit tests, but for now we need these here.
5864 RegisterAllCoreRPCCommands (tableRPC);
@@ -80,6 +86,7 @@ TestingSetup::~TestingSetup()
8086 UnregisterNodeSignals (GetNodeSignals ());
8187 threadGroup.interrupt_all ();
8288 threadGroup.join_all ();
89+ GetMainSignals ().UnregisterBackgroundSignalScheduler ();
8390 UnloadBlockIndex ();
8491 delete pcoinsTip;
8592 delete pcoinsdbview;
Original file line number Diff line number Diff line change 66#define PIVX_TEST_TEST_PIVX_H
77
88#include " fs.h"
9+ #include " scheduler.h"
910#include " txdb.h"
1011
1112#include < boost/thread.hpp>
@@ -48,6 +49,7 @@ struct TestingSetup: public BasicTestingSetup {
4849 fs::path pathTemp;
4950 boost::thread_group threadGroup;
5051 CConnman* connman;
52+ CScheduler scheduler;
5153 ECCVerifyHandle globalVerifyHandle;
5254
5355 TestingSetup ();
Original file line number Diff line number Diff line change 55// file COPYING or http://www.opensource.org/licenses/mit-license.php.
66
77#include " validationinterface.h"
8+ #include " init.h"
9+ #include " scheduler.h"
810
911#include < unordered_map>
1012#include < boost/signals2/signal.hpp>
@@ -39,6 +41,7 @@ struct MainSignalsInstance {
3941 /* * Notifies listeners of a block validation result */
4042 boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked;
4143
44+ CScheduler *m_scheduler = nullptr ;
4245 std::unordered_map<CValidationInterface*, ValidationInterfaceConnections> m_connMainSignals;
4346};
4447
@@ -48,6 +51,15 @@ CMainSignals::CMainSignals() {
4851 m_internals.reset (new MainSignalsInstance ());
4952}
5053
54+ void CMainSignals::RegisterBackgroundSignalScheduler (CScheduler& scheduler) {
55+ assert (!m_internals->m_scheduler );
56+ m_internals->m_scheduler = &scheduler;
57+ }
58+
59+ void CMainSignals::UnregisterBackgroundSignalScheduler () {
60+ m_internals->m_scheduler = nullptr ;
61+ }
62+
5163CMainSignals& GetMainSignals ()
5264{
5365 return g_signals;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ class CConnman;
1818class CValidationInterface ;
1919class CValidationState ;
2020class uint256 ;
21+ class CScheduler ;
2122
2223// These functions dispatch to one or all registered wallets
2324
@@ -53,9 +54,15 @@ class CMainSignals {
5354 friend void ::RegisterValidationInterface (CValidationInterface*);
5455 friend void ::UnregisterValidationInterface (CValidationInterface*);
5556 friend void ::UnregisterAllValidationInterfaces ();
57+
5658public:
5759 CMainSignals ();
5860
61+ /* * Register a CScheduler to give callbacks which should run in the background (may only be called once) */
62+ void RegisterBackgroundSignalScheduler (CScheduler& scheduler);
63+ /* * Unregister a CScheduler to give callbacks which should run in the background - these callbacks will now be dropped! */
64+ void UnregisterBackgroundSignalScheduler ();
65+
5966 void UpdatedBlockTip (const CBlockIndex *, const CBlockIndex *, bool fInitialDownload );
6067 void TransactionAddedToMempool (const CTransactionRef &ptxn);
6168 void BlockConnected (const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted);
You can’t perform that action at this time.
0 commit comments