aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2019-01-25 01:11:17 -0500
committerMarcoFalke <falke.marco@gmail.com>2019-01-25 01:11:24 -0500
commitd14ef5721ffcf07321704dc21f1ab9df4952a44d (patch)
tree58dba5c266d908d3c7155988d281c24f13ad0071 /src
parent72bd4ab867e3be0d8410403d9641c08288d343e3 (diff)
parentb09dab0f2de37be3c96f5087ee7bd61d7262aa76 (diff)
downloadbitcoin-d14ef5721ffcf07321704dc21f1ab9df4952a44d.tar.xz
Merge #15233: Prevent mutex lock fail even if --enable-debug
b09dab0f2d Prevent mutex lock fail even if --enable-debug (Akio Nakamura) Pull request description: This PR intends to resolve #15227. ```configure --enable-debug``` enables ```#ifdef DEBUG_LOCKORDER```. Then ```lockdata``` (in sync.cpp) will be initialized same as other static objects. But unfortunately, ```lockdata.push_lock()``` was called before its initialization (via initializing ```signatureCache``` which is declared in ```script/sigcache.cpp```) on macOS. This PR apply the "Construct On First Use Idiom" to ```lockdata``` to prevent it. edited --- fix typo. Tree-SHA512: 59df99ef78a335b1b7ebed7207d4719ea4412900eea38739f6e8eaaba1f594e1950044851659ce83f4f69813fc96978244bd176676e1aa2277c813ede832e6fb
Diffstat (limited to 'src')
-rw-r--r--src/sync.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/sync.cpp b/src/sync.cpp
index 30811f5f89..23ca866e53 100644
--- a/src/sync.cpp
+++ b/src/sync.cpp
@@ -73,7 +73,11 @@ struct LockData {
LockOrders lockorders;
InvLockOrders invlockorders;
std::mutex dd_mutex;
-} static lockdata;
+};
+LockData& GetLockData() {
+ static LockData lockdata;
+ return lockdata;
+}
static thread_local LockStack g_lockstack;
@@ -109,6 +113,7 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
static void push_lock(void* c, const CLockLocation& locklocation)
{
+ LockData& lockdata = GetLockData();
std::lock_guard<std::mutex> lock(lockdata.dd_mutex);
g_lockstack.push_back(std::make_pair(c, locklocation));
@@ -173,6 +178,7 @@ void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLi
void DeleteLock(void* cs)
{
+ LockData& lockdata = GetLockData();
if (!lockdata.available) {
// We're already shutting down.
return;