@@ -33,22 +33,20 @@ void PrintLockContention(const char* pszName, const char* pszFile, int nLine)
33
33
//
34
34
35
35
struct CLockLocation {
36
- CLockLocation (const char * pszName, const char * pszFile, int nLine, bool fTryIn )
36
+ CLockLocation (const char * pszName, const char * pszFile, int nLine)
37
37
{
38
38
mutexName = pszName;
39
39
sourceFile = pszFile;
40
40
sourceLine = nLine;
41
- fTry = fTryIn ;
42
41
}
43
42
44
43
std::string ToString () const
45
44
{
46
- return mutexName + " " + sourceFile + " :" + itostr (sourceLine) + ( fTry ? " (TRY) " : " " ) ;
45
+ return mutexName + " " + sourceFile + " :" + itostr (sourceLine);
47
46
}
48
47
49
48
std::string MutexName () const { return mutexName; }
50
49
51
- bool fTry ;
52
50
private:
53
51
std::string mutexName;
54
52
std::string sourceFile;
@@ -64,52 +62,23 @@ static boost::thread_specific_ptr<LockStack> lockstack;
64
62
65
63
static void potential_deadlock_detected (const std::pair<void *, void *>& mismatch, const LockStack& s1, const LockStack& s2)
66
64
{
67
- // We attempt to not assert on probably-not deadlocks by assuming that
68
- // a try lock will immediately have otherwise bailed if it had
69
- // failed to get the lock
70
- // We do this by, for the locks which triggered the potential deadlock,
71
- // in either lockorder, checking that the second of the two which is locked
72
- // is only a TRY_LOCK, ignoring locks if they are reentrant.
73
- bool firstLocked = false ;
74
- bool secondLocked = false ;
75
- bool onlyMaybeDeadlock = false ;
76
-
77
65
LogPrintf (" POTENTIAL DEADLOCK DETECTED\n " );
78
66
LogPrintf (" Previous lock order was:\n " );
79
67
BOOST_FOREACH (const PAIRTYPE (void *, CLockLocation) & i, s2) {
80
- if (i.first == mismatch.first ) {
68
+ if (i.first == mismatch.first )
81
69
LogPrintf (" (1)" );
82
- if (!firstLocked && secondLocked && i.second .fTry )
83
- onlyMaybeDeadlock = true ;
84
- firstLocked = true ;
85
- }
86
- if (i.first == mismatch.second ) {
70
+ if (i.first == mismatch.second )
87
71
LogPrintf (" (2)" );
88
- if (!secondLocked && firstLocked && i.second .fTry )
89
- onlyMaybeDeadlock = true ;
90
- secondLocked = true ;
91
- }
92
72
LogPrintf (" %s\n " , i.second .ToString ());
93
73
}
94
- firstLocked = false ;
95
- secondLocked = false ;
96
74
LogPrintf (" Current lock order is:\n " );
97
75
BOOST_FOREACH (const PAIRTYPE (void *, CLockLocation) & i, s1) {
98
- if (i.first == mismatch.first ) {
76
+ if (i.first == mismatch.first )
99
77
LogPrintf (" (1)" );
100
- if (!firstLocked && secondLocked && i.second .fTry )
101
- onlyMaybeDeadlock = true ;
102
- firstLocked = true ;
103
- }
104
- if (i.first == mismatch.second ) {
78
+ if (i.first == mismatch.second )
105
79
LogPrintf (" (2)" );
106
- if (!secondLocked && firstLocked && i.second .fTry )
107
- onlyMaybeDeadlock = true ;
108
- secondLocked = true ;
109
- }
110
80
LogPrintf (" %s\n " , i.second .ToString ());
111
81
}
112
- assert (onlyMaybeDeadlock);
113
82
}
114
83
115
84
static void push_lock (void * c, const CLockLocation& locklocation, bool fTry )
@@ -132,8 +101,10 @@ static void push_lock(void* c, const CLockLocation& locklocation, bool fTry)
132
101
lockorders[p1] = (*lockstack);
133
102
134
103
std::pair<void *, void *> p2 = std::make_pair (c, i.first );
135
- if (lockorders.count (p2))
104
+ if (lockorders.count (p2)) {
136
105
potential_deadlock_detected (p1, lockorders[p2], lockorders[p1]);
106
+ break ;
107
+ }
137
108
}
138
109
}
139
110
dd_mutex.unlock ();
@@ -148,7 +119,7 @@ static void pop_lock()
148
119
149
120
void EnterCritical (const char * pszName, const char * pszFile, int nLine, void * cs, bool fTry )
150
121
{
151
- push_lock (cs, CLockLocation (pszName, pszFile, nLine, fTry ), fTry );
122
+ push_lock (cs, CLockLocation (pszName, pszFile, nLine), fTry );
152
123
}
153
124
154
125
void LeaveCritical ()
0 commit comments