mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
refactor: Add LockStackItem type alias
This commit is contained in:
19
src/sync.cpp
19
src/sync.cpp
@@ -7,15 +7,17 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <tinyformat.h>
|
|
||||||
|
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
|
#include <tinyformat.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/threadnames.h>
|
#include <util/threadnames.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifdef DEBUG_LOCKCONTENTION
|
#ifdef DEBUG_LOCKCONTENTION
|
||||||
#if !defined(HAVE_THREAD_LOCAL)
|
#if !defined(HAVE_THREAD_LOCAL)
|
||||||
@@ -73,7 +75,8 @@ private:
|
|||||||
int sourceLine;
|
int sourceLine;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<std::pair<void*, CLockLocation> > LockStack;
|
using LockStackItem = std::pair<void*, CLockLocation>;
|
||||||
|
using LockStack = std::vector<LockStackItem>;
|
||||||
typedef std::map<std::pair<void*, void*>, LockStack> LockOrders;
|
typedef std::map<std::pair<void*, void*>, LockStack> LockOrders;
|
||||||
typedef std::set<std::pair<void*, void*> > InvLockOrders;
|
typedef std::set<std::pair<void*, void*> > InvLockOrders;
|
||||||
|
|
||||||
@@ -96,7 +99,7 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
|
|||||||
{
|
{
|
||||||
LogPrintf("POTENTIAL DEADLOCK DETECTED\n");
|
LogPrintf("POTENTIAL DEADLOCK DETECTED\n");
|
||||||
LogPrintf("Previous lock order was:\n");
|
LogPrintf("Previous lock order was:\n");
|
||||||
for (const std::pair<void*, CLockLocation> & i : s2) {
|
for (const LockStackItem& i : s2) {
|
||||||
if (i.first == mismatch.first) {
|
if (i.first == mismatch.first) {
|
||||||
LogPrintf(" (1)"); /* Continued */
|
LogPrintf(" (1)"); /* Continued */
|
||||||
}
|
}
|
||||||
@@ -106,7 +109,7 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
|
|||||||
LogPrintf(" %s\n", i.second.ToString());
|
LogPrintf(" %s\n", i.second.ToString());
|
||||||
}
|
}
|
||||||
LogPrintf("Current lock order is:\n");
|
LogPrintf("Current lock order is:\n");
|
||||||
for (const std::pair<void*, CLockLocation> & i : s1) {
|
for (const LockStackItem& i : s1) {
|
||||||
if (i.first == mismatch.first) {
|
if (i.first == mismatch.first) {
|
||||||
LogPrintf(" (1)"); /* Continued */
|
LogPrintf(" (1)"); /* Continued */
|
||||||
}
|
}
|
||||||
@@ -129,7 +132,7 @@ static void push_lock(void* c, const CLockLocation& locklocation)
|
|||||||
|
|
||||||
g_lockstack.push_back(std::make_pair(c, locklocation));
|
g_lockstack.push_back(std::make_pair(c, locklocation));
|
||||||
|
|
||||||
for (const std::pair<void*, CLockLocation>& i : g_lockstack) {
|
for (const LockStackItem& i : g_lockstack) {
|
||||||
if (i.first == c)
|
if (i.first == c)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -175,14 +178,14 @@ void LeaveCritical()
|
|||||||
std::string LocksHeld()
|
std::string LocksHeld()
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
for (const std::pair<void*, CLockLocation>& i : g_lockstack)
|
for (const LockStackItem& i : g_lockstack)
|
||||||
result += i.second.ToString() + std::string("\n");
|
result += i.second.ToString() + std::string("\n");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 std::pair<void*, CLockLocation>& i : g_lockstack)
|
for (const LockStackItem& i : g_lockstack)
|
||||||
if (i.first == cs)
|
if (i.first == cs)
|
||||||
return;
|
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());
|
||||||
@@ -191,7 +194,7 @@ void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine,
|
|||||||
|
|
||||||
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 std::pair<void*, CLockLocation>& i : g_lockstack) {
|
for (const LockStackItem& i : g_lockstack) {
|
||||||
if (i.first == cs) {
|
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user