Skip to content

Commit

Permalink
Merge #15233: Prevent mutex lock fail even if --enable-debug
Browse files Browse the repository at this point in the history
b09dab0 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
  • Loading branch information
MarcoFalke committed Jan 25, 2019
2 parents 72bd4ab + b09dab0 commit d14ef57
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d14ef57

Please sign in to comment.