aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-06-08 06:54:53 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-06-08 06:55:00 -0400
commit399a0d9dc7a15bd4a9184ba19e1f251cfbb450c8 (patch)
treec4e0cb9b77b89f1c0d0cd3d16a22b2e5931e4d9c /src
parent807b9f811479a2b5a4b29e44fe915e054bd92fc3 (diff)
parent1a9ef1d398dd14728b6bc67a89139cdf827c9753 (diff)
downloadbitcoin-399a0d9dc7a15bd4a9184ba19e1f251cfbb450c8.tar.xz
Merge #19180: refactor: Replace RecursiveMutex with Mutex in Shutdown()
1a9ef1d398dd14728b6bc67a89139cdf827c9753 refactor: Replace RecursiveMutex with Mutex in Shutdown() (Hennadii Stepanov) Pull request description: Step by step, going to replace all of the `RecursiveMutex` instances with the `Mutex` ones throughout the code base :) Not sure if it is possible in all cases though... This one is a low-hanging fruit. ACKs for top commit: MarcoFalke: ACK 1a9ef1d398dd14728b6bc67a89139cdf827c9753 Shutdown is not recursive, so the same thread can never lock twice (UB) vasild: ACK 1a9ef1d3 verified manually that `Shutdown()` is not called from places that could be called from inside `Shutdown()`. Tree-SHA512: 362a507b1a6f97dc351f708224aedbfe4bee03c4398f394d78ee31c24d76a7012ffff0e6766866cd5fd9a8e0d8840f05a2741111fe583aa20d45f0af3df0dcfa
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 4c5c0051ca..760294723b 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -18,6 +18,7 @@
#include <compat/sanity.h>
#include <consensus/validation.h>
#include <fs.h>
+#include <hash.h>
#include <httprpc.h>
#include <httpserver.h>
#include <index/blockfilterindex.h>
@@ -42,6 +43,7 @@
#include <script/sigcache.h>
#include <script/standard.h>
#include <shutdown.h>
+#include <sync.h>
#include <timedata.h>
#include <torcontrol.h>
#include <txdb.h>
@@ -53,8 +55,6 @@
#include <util/threadnames.h>
#include <util/translation.h>
#include <validation.h>
-#include <hash.h>
-
#include <validationinterface.h>
#include <walletinitinterface.h>
@@ -171,11 +171,10 @@ void Interrupt(NodeContext& node)
void Shutdown(NodeContext& node)
{
+ static Mutex g_shutdown_mutex;
+ TRY_LOCK(g_shutdown_mutex, lock_shutdown);
+ if (!lock_shutdown) return;
LogPrintf("%s: In progress...\n", __func__);
- static RecursiveMutex cs_Shutdown;
- TRY_LOCK(cs_Shutdown, lockShutdown);
- if (!lockShutdown)
- return;
/// Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
/// for example if the data directory was found to be locked.