Auto merge of #5064 - str4d:5048-mutex-lock-failure, r=str4d

Prevent mutex lock fail even if --enable-debug

Cherry-picked from upstream PR bitcoin/bitcoin#15233.

Closes zcash/zcash#5048.
This commit is contained in:
Homu 2021-04-20 07:20:46 +00:00
commit 05c0c7c573
1 changed files with 7 additions and 1 deletions

View File

@ -70,7 +70,11 @@ struct LockData {
LockOrders lockorders; LockOrders lockorders;
InvLockOrders invlockorders; InvLockOrders invlockorders;
boost::mutex dd_mutex; boost::mutex dd_mutex;
} static lockdata; };
LockData& GetLockData() {
static LockData lockdata;
return lockdata;
}
boost::thread_specific_ptr<LockStack> lockstack; boost::thread_specific_ptr<LockStack> lockstack;
@ -129,6 +133,7 @@ static void push_lock(void* c, const CLockLocation& locklocation, bool fTry)
if (lockstack.get() == NULL) if (lockstack.get() == NULL)
lockstack.reset(new LockStack); lockstack.reset(new LockStack);
LockData& lockdata = GetLockData();
boost::unique_lock<boost::mutex> lock(lockdata.dd_mutex); boost::unique_lock<boost::mutex> lock(lockdata.dd_mutex);
(*lockstack).push_back(std::make_pair(c, locklocation)); (*lockstack).push_back(std::make_pair(c, locklocation));
@ -195,6 +200,7 @@ void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLi
void DeleteLock(void* cs) void DeleteLock(void* cs)
{ {
LockData& lockdata = GetLockData();
if (!lockdata.available) { if (!lockdata.available) {
// We're already shutting down. // We're already shutting down.
return; return;