Changeset View
Changeset View
Standalone View
Standalone View
src/sync.cpp
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | |||||
void EnterCritical(const char *pszName, const char *pszFile, int nLine, | void EnterCritical(const char *pszName, const char *pszFile, int nLine, | ||||
void *cs, bool fTry) { | void *cs, bool fTry) { | ||||
push_lock(cs, CLockLocation(pszName, pszFile, nLine, fTry, | push_lock(cs, CLockLocation(pszName, pszFile, nLine, fTry, | ||||
util::ThreadGetInternalName())); | util::ThreadGetInternalName())); | ||||
} | } | ||||
void CheckLastCritical(void *cs, std::string &lockname, const char *guardname, | void CheckLastCritical(void *cs, std::string &lockname, const char *guardname, | ||||
const char *file, int line) { | const char *file, int line) { | ||||
{ | |||||
LockData &lockdata = GetLockData(); | LockData &lockdata = GetLockData(); | ||||
std::lock_guard<std::mutex> lock(lockdata.dd_mutex); | std::lock_guard<std::mutex> lock(lockdata.dd_mutex); | ||||
const LockStack &lock_stack = | const LockStack &lock_stack = | ||||
lockdata.m_lock_stacks[std::this_thread::get_id()]; | lockdata.m_lock_stacks[std::this_thread::get_id()]; | ||||
if (!lock_stack.empty()) { | if (!lock_stack.empty()) { | ||||
const auto &lastlock = lock_stack.back(); | const auto &lastlock = lock_stack.back(); | ||||
if (lastlock.first == cs) { | if (lastlock.first == cs) { | ||||
lockname = lastlock.second.Name(); | lockname = lastlock.second.Name(); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
LogPrintf("INCONSISTENT LOCK ORDER DETECTED\n"); | |||||
LogPrintf("Current lock order (least recent first) is:\n"); | |||||
for (const LockStackItem &i : lock_stack) { | |||||
LogPrintf(" %s\n", i.second.ToString()); | |||||
} | } | ||||
throw std::system_error( | if (g_debug_lockorder_abort) { | ||||
EPERM, std::generic_category(), | tfm::format(std::cerr, | ||||
strprintf("%s:%s %s was not most recent critical section locked", file, | "%s:%s %s was not most recent critical section locked, " | ||||
line, guardname)); | "details in debug log.\n", | ||||
file, line, guardname); | |||||
abort(); | |||||
} | |||||
throw std::logic_error( | |||||
strprintf("%s was not most recent critical section locked", guardname)); | |||||
} | } | ||||
void LeaveCritical() { | void LeaveCritical() { | ||||
pop_lock(); | pop_lock(); | ||||
} | } | ||||
std::string LocksHeld() { | std::string LocksHeld() { | ||||
LockData &lockdata = GetLockData(); | LockData &lockdata = GetLockData(); | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |