refactor: Refactor duplicated code into LockHeld()

pull/18881/head
Hennadii Stepanov 5 years ago
parent f511f61dda
commit 58e6881bc5
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

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

Loading…
Cancel
Save