Skip to content

Commit 8d8921a

Browse files
committed
refactor: Add LockStackItem type alias
1 parent 458992b commit 8d8921a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/sync.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
#endif
88

99
#include <sync.h>
10-
#include <tinyformat.h>
1110

1211
#include <logging.h>
12+
#include <tinyformat.h>
1313
#include <util/strencodings.h>
1414
#include <util/threadnames.h>
1515

1616
#include <map>
1717
#include <set>
1818
#include <system_error>
19+
#include <utility>
20+
#include <vector>
1921

2022
#ifdef DEBUG_LOCKCONTENTION
2123
#if !defined(HAVE_THREAD_LOCAL)
@@ -73,7 +75,8 @@ struct CLockLocation {
7375
int sourceLine;
7476
};
7577

76-
typedef std::vector<std::pair<void*, CLockLocation> > LockStack;
78+
using LockStackItem = std::pair<void*, CLockLocation>;
79+
using LockStack = std::vector<LockStackItem>;
7780
typedef std::map<std::pair<void*, void*>, LockStack> LockOrders;
7881
typedef std::set<std::pair<void*, void*> > InvLockOrders;
7982

@@ -96,7 +99,7 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
9699
{
97100
LogPrintf("POTENTIAL DEADLOCK DETECTED\n");
98101
LogPrintf("Previous lock order was:\n");
99-
for (const std::pair<void*, CLockLocation> & i : s2) {
102+
for (const LockStackItem& i : s2) {
100103
if (i.first == mismatch.first) {
101104
LogPrintf(" (1)"); /* Continued */
102105
}
@@ -106,7 +109,7 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
106109
LogPrintf(" %s\n", i.second.ToString());
107110
}
108111
LogPrintf("Current lock order is:\n");
109-
for (const std::pair<void*, CLockLocation> & i : s1) {
112+
for (const LockStackItem& i : s1) {
110113
if (i.first == mismatch.first) {
111114
LogPrintf(" (1)"); /* Continued */
112115
}
@@ -129,7 +132,7 @@ static void push_lock(void* c, const CLockLocation& locklocation)
129132

130133
g_lockstack.push_back(std::make_pair(c, locklocation));
131134

132-
for (const std::pair<void*, CLockLocation>& i : g_lockstack) {
135+
for (const LockStackItem& i : g_lockstack) {
133136
if (i.first == c)
134137
break;
135138

@@ -175,14 +178,14 @@ void LeaveCritical()
175178
std::string LocksHeld()
176179
{
177180
std::string result;
178-
for (const std::pair<void*, CLockLocation>& i : g_lockstack)
181+
for (const LockStackItem& i : g_lockstack)
179182
result += i.second.ToString() + std::string("\n");
180183
return result;
181184
}
182185

183186
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
184187
{
185-
for (const std::pair<void*, CLockLocation>& i : g_lockstack)
188+
for (const LockStackItem& i : g_lockstack)
186189
if (i.first == cs)
187190
return;
188191
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,
191194

192195
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
193196
{
194-
for (const std::pair<void*, CLockLocation>& i : g_lockstack) {
197+
for (const LockStackItem& i : g_lockstack) {
195198
if (i.first == cs) {
196199
tfm::format(std::cerr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld());
197200
abort();

0 commit comments

Comments
 (0)