Skip to content

Commit 8d2f847

Browse files
jonatackmartinus
andcommitted
sync: inline lock contention logging macro to fix time duration
Co-authored-by: Martin Ankerl <[email protected]>
1 parent 6718fbe commit 8d2f847

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

src/sync.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <sync.h>
1010

1111
#include <logging.h>
12-
#include <logging/timer.h>
1312
#include <tinyformat.h>
1413
#include <util/strencodings.h>
1514
#include <util/threadnames.h>
@@ -24,11 +23,6 @@
2423
#include <utility>
2524
#include <vector>
2625

27-
void LockContention(const char* pszName, const char* pszFile, int nLine)
28-
{
29-
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
30-
}
31-
3226
#ifdef DEBUG_LOCKORDER
3327
//
3428
// Early deadlock detection.

src/sync.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef BITCOIN_SYNC_H
77
#define BITCOIN_SYNC_H
88

9+
#include <logging.h>
10+
#include <logging/timer.h>
911
#include <threadsafety.h>
1012
#include <util/macros.h>
1113

@@ -126,9 +128,6 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
126128
/** Wrapped mutex: supports waiting but not recursive locking */
127129
typedef AnnotatedMixin<std::mutex> Mutex;
128130

129-
/** Prints a lock contention to the log */
130-
void LockContention(const char* pszName, const char* pszFile, int nLine);
131-
132131
/** Wrapper around std::unique_lock style lock for Mutex. */
133132
template <typename Mutex, typename Base = typename Mutex::UniqueLock>
134133
class SCOPED_LOCKABLE UniqueLock : public Base
@@ -138,7 +137,7 @@ class SCOPED_LOCKABLE UniqueLock : public Base
138137
{
139138
EnterCritical(pszName, pszFile, nLine, Base::mutex());
140139
if (Base::try_lock()) return;
141-
LockContention(pszName, pszFile, nLine); // log the contention
140+
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("lock contention %s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
142141
Base::lock();
143142
}
144143

0 commit comments

Comments
 (0)