Skip to content

Commit d14ef57

Browse files
author
MarcoFalke
committed
Merge #15233: Prevent mutex lock fail even if --enable-debug
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
2 parents 72bd4ab + b09dab0 commit d14ef57

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/sync.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ struct LockData {
7373
LockOrders lockorders;
7474
InvLockOrders invlockorders;
7575
std::mutex dd_mutex;
76-
} static lockdata;
76+
};
77+
LockData& GetLockData() {
78+
static LockData lockdata;
79+
return lockdata;
80+
}
7781

7882
static thread_local LockStack g_lockstack;
7983

@@ -109,6 +113,7 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
109113

110114
static void push_lock(void* c, const CLockLocation& locklocation)
111115
{
116+
LockData& lockdata = GetLockData();
112117
std::lock_guard<std::mutex> lock(lockdata.dd_mutex);
113118

114119
g_lockstack.push_back(std::make_pair(c, locklocation));
@@ -173,6 +178,7 @@ void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLi
173178

174179
void DeleteLock(void* cs)
175180
{
181+
LockData& lockdata = GetLockData();
176182
if (!lockdata.available) {
177183
// We're already shutting down.
178184
return;

0 commit comments

Comments
 (0)