sync: inline lock contention logging macro to fix time duration

Co-authored-by: Martin Ankerl <martin.ankerl@gmail.com>
pull/22904/head
Jon Atack 3 years ago
parent 6718fbe90a
commit 8d2f847ed9
No known key found for this signature in database
GPG Key ID: 4F5721B3D0E3921D

@ -9,7 +9,6 @@
#include <sync.h> #include <sync.h>
#include <logging.h> #include <logging.h>
#include <logging/timer.h>
#include <tinyformat.h> #include <tinyformat.h>
#include <util/strencodings.h> #include <util/strencodings.h>
#include <util/threadnames.h> #include <util/threadnames.h>
@ -24,11 +23,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
void LockContention(const char* pszName, const char* pszFile, int nLine)
{
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
}
#ifdef DEBUG_LOCKORDER #ifdef DEBUG_LOCKORDER
// //
// Early deadlock detection. // Early deadlock detection.

@ -6,6 +6,8 @@
#ifndef BITCOIN_SYNC_H #ifndef BITCOIN_SYNC_H
#define BITCOIN_SYNC_H #define BITCOIN_SYNC_H
#include <logging.h>
#include <logging/timer.h>
#include <threadsafety.h> #include <threadsafety.h>
#include <util/macros.h> #include <util/macros.h>
@ -126,9 +128,6 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
/** Wrapped mutex: supports waiting but not recursive locking */ /** Wrapped mutex: supports waiting but not recursive locking */
typedef AnnotatedMixin<std::mutex> Mutex; typedef AnnotatedMixin<std::mutex> Mutex;
/** Prints a lock contention to the log */
void LockContention(const char* pszName, const char* pszFile, int nLine);
/** Wrapper around std::unique_lock style lock for Mutex. */ /** Wrapper around std::unique_lock style lock for Mutex. */
template <typename Mutex, typename Base = typename Mutex::UniqueLock> template <typename Mutex, typename Base = typename Mutex::UniqueLock>
class SCOPED_LOCKABLE UniqueLock : public Base class SCOPED_LOCKABLE UniqueLock : public Base
@ -138,7 +137,7 @@ private:
{ {
EnterCritical(pszName, pszFile, nLine, Base::mutex()); EnterCritical(pszName, pszFile, nLine, Base::mutex());
if (Base::try_lock()) return; if (Base::try_lock()) return;
LockContention(pszName, pszFile, nLine); // log the contention LOG_TIME_MICROS_WITH_CATEGORY(strprintf("lock contention %s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
Base::lock(); Base::lock();
} }

Loading…
Cancel
Save