0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

refactor: Refactor duplicated code into LockHeld()

This commit is contained in:
Hennadii Stepanov 2020-05-18 17:45:46 +03:00
parent f511f61dda
commit 58e6881bc5
No known key found for this signature in database
GPG key ID: 410108112E7EA81F

View file

@ -185,23 +185,27 @@ std::string LocksHeld()
return result;
}
static bool LockHeld(void* mutex)
{
for (const LockStackItem& i : g_lockstack) {
if (i.first == mutex) return true;
}
return false;
}
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
{
for (const LockStackItem& i : g_lockstack)
if (i.first == cs)
return;
if (LockHeld(cs)) return;
tfm::format(std::cerr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld());
abort();
}
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
{
for (const LockStackItem& i : g_lockstack) {
if (i.first == cs) {
tfm::format(std::cerr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld());
abort();
}
}
if (!LockHeld(cs)) return;
tfm::format(std::cerr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld());
abort();
}
void DeleteLock(void* cs)