Skip to content

Commit 7e69873

Browse files
committed
sync: remove DEBUG_LOCKCONTENTION preprocessor directives
to allow logging the lock contentions without the need to define DEBUG_LOCKCONTENTION at compile time.
1 parent 9b08006 commit 7e69873

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/sync.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,10 @@
2424
#include <utility>
2525
#include <vector>
2626

27-
#ifdef DEBUG_LOCKCONTENTION
28-
#if !defined(HAVE_THREAD_LOCAL)
29-
static_assert(false, "thread_local is not supported");
30-
#endif
3127
void LockContention(const char* pszName, const char* pszFile, int nLine)
3228
{
3329
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
3430
}
35-
#endif /* DEBUG_LOCKCONTENTION */
3631

3732
#ifdef DEBUG_LOCKORDER
3833
//

src/sync.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,8 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
126126
/** Wrapped mutex: supports waiting but not recursive locking */
127127
typedef AnnotatedMixin<std::mutex> Mutex;
128128

129-
#ifdef DEBUG_LOCKCONTENTION
130129
/** Prints a lock contention to the log */
131130
void LockContention(const char* pszName, const char* pszFile, int nLine);
132-
#endif
133131

134132
/** Wrapper around std::unique_lock style lock for Mutex. */
135133
template <typename Mutex, typename Base = typename Mutex::UniqueLock>
@@ -139,22 +137,18 @@ class SCOPED_LOCKABLE UniqueLock : public Base
139137
void Enter(const char* pszName, const char* pszFile, int nLine)
140138
{
141139
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();
150143
}
151144

152145
bool TryEnter(const char* pszName, const char* pszFile, int nLine)
153146
{
154147
EnterCritical(pszName, pszFile, nLine, Base::mutex(), true);
155148
Base::try_lock();
156-
if (!Base::owns_lock())
149+
if (!Base::owns_lock()) {
157150
LeaveCritical();
151+
}
158152
return Base::owns_lock();
159153
}
160154

0 commit comments

Comments
 (0)