Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251}253void LeaveCritical()254{255pop_lock();256}258static std::string LocksHeld()259{260LockData& lockdata = GetLockData();261STDLOCK(lockdata.dd_mutex);263const LockStack& lock_stack = lockdata.m_lock_stacks[std::this_thread::get_id()];264std::string result;265for (const LockStackItem& i : lock_stack)266result += i.second.ToString() + std::string("\n");267return result;268}270static bool LockHeld(void* mutex)271{272LockData& lockdata = GetLockData();273STDLOCK(lockdata.dd_mutex);275const LockStack& lock_stack = lockdata.m_lock_stacks[std::this_thread::get_id()];276for (const LockStackItem& i : lock_stack) {277if (i.first == mutex) return true;278}280return false;281}283template <typename MutexType>284void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs)285{286if (LockHeld(cs)) return;287tfm::format(std::cerr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld());288abort();289}290template void AssertLockHeldInternal(const char*, const char*, int, Mutex*);291template void AssertLockHeldInternal(const char*, const char*, int, RecursiveMutex*);293template <typename MutexType>294void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs)295{296if (!LockHeld(cs)) return;297tfm::format(std::cerr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld());298abort();299}300template void AssertLockNotHeldInternal(const char*, const char*, int, Mutex*);301template void AssertLockNotHeldInternal(const char*, const char*, int, RecursiveMutex*);303void DeleteLock(void* cs)304{305LockData& lockdata = GetLockData();306STDLOCK(lockdata.dd_mutex);307const LockPair item = std::make_pair(cs, nullptr);308LockOrders::iterator it = lockdata.lockorders.lower_bound(item);309while (it != lockdata.lockorders.end() && it->first.first == cs) {310const LockPair invitem = std::make_pair(it->first.second, it->first.first);311lockdata.invlockorders.erase(invitem);312lockdata.lockorders.erase(it++);313}314InvLockOrders::iterator invit = lockdata.invlockorders.lower_bound(item);315while (invit != lockdata.invlockorders.end() && invit->first == cs) {316const LockPair invinvitem = std::make_pair(invit->second, invit->first);317lockdata.lockorders.erase(invinvitem);318lockdata.invlockorders.erase(invit++);319}320}322bool LockStackEmpty()323{324LockData& lockdata = GetLockData();325STDLOCK(lockdata.dd_mutex);326const auto it = lockdata.m_lock_stacks.find(std::this_thread::get_id());327if (it == lockdata.m_lock_stacks.end()) {328return true;329}330return it->second.empty();331}333bool g_debug_lockorder_abort = true;335#endif /* DEBUG_LOCKORDER */
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.