3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
5
5
#include < sync.h>
6
+ #include < tinyformat.h>
6
7
7
8
#include < logging.h>
8
9
#include < util/strencodings.h>
10
+ #include < util/threadnames.h>
9
11
10
12
#include < stdio.h>
11
13
@@ -37,23 +39,30 @@ void PrintLockContention(const char* pszName, const char* pszFile, int nLine)
37
39
//
38
40
39
41
struct CLockLocation {
40
- CLockLocation (const char * pszName, const char * pszFile, int nLine, bool fTryIn )
41
- {
42
- mutexName = pszName;
43
- sourceFile = pszFile;
44
- sourceLine = nLine;
45
- fTry = fTryIn ;
46
- }
42
+ CLockLocation (
43
+ const char * pszName,
44
+ const char * pszFile,
45
+ int nLine,
46
+ bool fTryIn ,
47
+ const std::string& thread_name)
48
+ : fTry (fTryIn ),
49
+ mutexName (pszName),
50
+ sourceFile(pszFile),
51
+ m_thread_name(thread_name),
52
+ sourceLine(nLine) {}
47
53
48
54
std::string ToString () const
49
55
{
50
- return mutexName + " " + sourceFile + " :" + itostr (sourceLine) + (fTry ? " (TRY)" : " " );
56
+ return tfm::format (
57
+ " %s %s:%s%s (in thread %s)" ,
58
+ mutexName, sourceFile, itostr (sourceLine), (fTry ? " (TRY)" : " " ), m_thread_name);
51
59
}
52
60
53
61
private:
54
62
bool fTry ;
55
63
std::string mutexName;
56
64
std::string sourceFile;
65
+ const std::string& m_thread_name;
57
66
int sourceLine;
58
67
};
59
68
@@ -125,7 +134,7 @@ static void push_lock(void* c, const CLockLocation& locklocation)
125
134
std::pair<void *, void *> p1 = std::make_pair (i.first , c);
126
135
if (lockdata.lockorders .count (p1))
127
136
continue ;
128
- lockdata.lockorders [p1] = g_lockstack;
137
+ lockdata.lockorders . emplace (p1, g_lockstack) ;
129
138
130
139
std::pair<void *, void *> p2 = std::make_pair (c, i.first );
131
140
lockdata.invlockorders .insert (p2);
@@ -141,7 +150,7 @@ static void pop_lock()
141
150
142
151
void EnterCritical (const char * pszName, const char * pszFile, int nLine, void * cs, bool fTry )
143
152
{
144
- push_lock (cs, CLockLocation (pszName, pszFile, nLine, fTry ));
153
+ push_lock (cs, CLockLocation (pszName, pszFile, nLine, fTry , util::ThreadGetInternalName () ));
145
154
}
146
155
147
156
void LeaveCritical ()
0 commit comments