@@ -126,10 +126,8 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
126
126
/* * Wrapped mutex: supports waiting but not recursive locking */
127
127
typedef AnnotatedMixin<std::mutex> Mutex;
128
128
129
- #ifdef DEBUG_LOCKCONTENTION
130
129
/* * Prints a lock contention to the log */
131
130
void LockContention (const char * pszName, const char * pszFile, int nLine);
132
- #endif
133
131
134
132
/* * Wrapper around std::unique_lock style lock for Mutex. */
135
133
template <typename Mutex, typename Base = typename Mutex::UniqueLock>
@@ -139,22 +137,18 @@ class SCOPED_LOCKABLE UniqueLock : public Base
139
137
void Enter (const char * pszName, const char * pszFile, int nLine)
140
138
{
141
139
EnterCritical (pszName, pszFile, nLine, Base::mutex ());
142
- #ifdef DEBUG_LOCKCONTENTION
143
- if (!Base::try_lock ()) {
144
- LockContention (pszName, pszFile, nLine); // log the contention
145
- #endif
146
- Base::lock ();
147
- #ifdef DEBUG_LOCKCONTENTION
148
- }
149
- #endif
140
+ if (Base::try_lock ()) return ;
141
+ LockContention (pszName, pszFile, nLine); // log the contention
142
+ Base::lock ();
150
143
}
151
144
152
145
bool TryEnter (const char * pszName, const char * pszFile, int nLine)
153
146
{
154
147
EnterCritical (pszName, pszFile, nLine, Base::mutex (), true );
155
148
Base::try_lock ();
156
- if (!Base::owns_lock ())
149
+ if (!Base::owns_lock ()) {
157
150
LeaveCritical ();
151
+ }
158
152
return Base::owns_lock ();
159
153
}
160
154
0 commit comments