Give CValidationInterface Support for calling notifications on the CScheduler Thread #10179
Merged
laanwj
merged 7 commits into
bitcoin:master
from
TheBlueMatt:2017-01-wallet-cache-inmempool-3
Jul 11, 2017
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff6a834
Use TestingSetup to DRY qt rpcnestedtests
TheBlueMatt 3a19fed
Make ValidationInterface signals-type-agnostic
TheBlueMatt cda1429
Give CMainSignals a reference to the global scheduler
TheBlueMatt 2fbf2db
Add default arg to CScheduler to schedule() a callback now
TheBlueMatt 08096bb
Support more than one CScheduler thread for serial clients
TheBlueMatt 3192975
Flush CValidationInterface callbacks prior to destruction
TheBlueMatt 1f668b6
Expose if CScheduler is being serviced, assert its not in EmptyQueue
TheBlueMatt
Jump to file or symbol
Failed to load files and symbols.
16
src/init.cpp
| @@ -215,6 +215,19 @@ void Shutdown() | ||
| fFeeEstimatesInitialized = false; | ||
| } | ||
| + // FlushStateToDisk generates a SetBestChain callback, which we should avoid missing | ||
| + FlushStateToDisk(); | ||
| + | ||
| + // After there are no more peers/RPC left to give us new data which may generate | ||
| + // CValidationInterface callbacks, flush them... | ||
| + GetMainSignals().FlushBackgroundCallbacks(); | ||
| + | ||
| + // Any future callbacks will be dropped. This should absolutely be safe - if | ||
| + // missing a callback results in an unrecoverable situation, unclean shutdown | ||
| + // would too. The only reason to do the above flushes is to let the wallet catch | ||
| + // up with our current chain to avoid any strange pruning edge cases and make | ||
| + // next startup faster by avoiding rescan. | ||
| + | ||
| { | ||
| LOCK(cs_main); | ||
| if (pcoinsTip != NULL) { | ||
| @@ -251,6 +264,7 @@ void Shutdown() | ||
| } | ||
| #endif | ||
| UnregisterAllValidationInterfaces(); | ||
| + GetMainSignals().UnregisterBackgroundSignalScheduler(); | ||
TheBlueMatt
Contributor
|
||
| #ifdef ENABLE_WALLET | ||
| for (CWalletRef pwallet : vpwallets) { | ||
| delete pwallet; | ||
| @@ -1203,6 +1217,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) | ||
| CScheduler::Function serviceLoop = boost::bind(&CScheduler::serviceQueue, &scheduler); | ||
| threadGroup.create_thread(boost::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop)); | ||
| + GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); | ||
| + | ||
| /* Start the RPC server already. It will be started in "warmup" mode | ||
| * and not really process calls already (but it will signify connections | ||
| * that the server is there and will be ready later). Warmup mode will | ||
Oops, something went wrong.
In commit "Give CMainSignals a reference to the global scheduler"
It seems like the right place for this unregister call would be earlier in Shutdown(), after scheduler thread is cancelled and the last signal is sent, for consistency with the register call, which is made when the scheduler thread is started.
This would let you flush the background queue when the signal scheduler is destroyed and not need separate
FlushBackgroundCallbacksandEmptyQueuecalls made in advance.Also this would bring shutdown code closer to an raii-style ordering, which should make cleanup easier in the future and would make the various object lifetimes a little easier to understand now.