@@ -75,7 +75,7 @@ struct LockData {
75
75
std::mutex dd_mutex;
76
76
} static lockdata;
77
77
78
- static thread_local std::unique_ptr< LockStack> lockstack ;
78
+ static thread_local LockStack g_lockstack ;
79
79
80
80
static void potential_deadlock_detected (const std::pair<void *, void *>& mismatch, const LockStack& s1, const LockStack& s2)
81
81
{
@@ -105,21 +105,18 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
105
105
106
106
static void push_lock (void * c, const CLockLocation& locklocation)
107
107
{
108
- if (!lockstack)
109
- lockstack.reset (new LockStack);
110
-
111
108
std::lock_guard<std::mutex> lock (lockdata.dd_mutex );
112
109
113
- lockstack-> push_back (std::make_pair (c, locklocation));
110
+ g_lockstack. push_back (std::make_pair (c, locklocation));
114
111
115
- for (const std::pair<void *, CLockLocation> & i : (*lockstack) ) {
112
+ for (const std::pair<void *, CLockLocation>& i : g_lockstack ) {
116
113
if (i.first == c)
117
114
break ;
118
115
119
116
std::pair<void *, void *> p1 = std::make_pair (i.first , c);
120
117
if (lockdata.lockorders .count (p1))
121
118
continue ;
122
- lockdata.lockorders [p1] = (*lockstack) ;
119
+ lockdata.lockorders [p1] = g_lockstack ;
123
120
124
121
std::pair<void *, void *> p2 = std::make_pair (c, i.first );
125
122
lockdata.invlockorders .insert (p2);
@@ -130,7 +127,7 @@ static void push_lock(void* c, const CLockLocation& locklocation)
130
127
131
128
static void pop_lock ()
132
129
{
133
- (*lockstack) .pop_back ();
130
+ g_lockstack .pop_back ();
134
131
}
135
132
136
133
void EnterCritical (const char * pszName, const char * pszFile, int nLine, void * cs, bool fTry )
@@ -146,14 +143,14 @@ void LeaveCritical()
146
143
std::string LocksHeld ()
147
144
{
148
145
std::string result;
149
- for (const std::pair<void *, CLockLocation> & i : *lockstack )
146
+ for (const std::pair<void *, CLockLocation>& i : g_lockstack )
150
147
result += i.second .ToString () + std::string (" \n " );
151
148
return result;
152
149
}
153
150
154
151
void AssertLockHeldInternal (const char * pszName, const char * pszFile, int nLine, void * cs)
155
152
{
156
- for (const std::pair<void *, CLockLocation> & i : *lockstack )
153
+ for (const std::pair<void *, CLockLocation>& i : g_lockstack )
157
154
if (i.first == cs)
158
155
return ;
159
156
fprintf (stderr, " Assertion failed: lock %s not held in %s:%i; locks held:\n %s" , pszName, pszFile, nLine, LocksHeld ().c_str ());
@@ -162,7 +159,7 @@ void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine,
162
159
163
160
void AssertLockNotHeldInternal (const char * pszName, const char * pszFile, int nLine, void * cs)
164
161
{
165
- for (const std::pair<void *, CLockLocation>& i : *lockstack ) {
162
+ for (const std::pair<void *, CLockLocation>& i : g_lockstack ) {
166
163
if (i.first == cs) {
167
164
fprintf (stderr, " Assertion failed: lock %s held in %s:%i; locks held:\n %s" , pszName, pszFile, nLine, LocksHeld ().c_str ());
168
165
abort ();
0 commit comments