From 7e698732836121912f179b7c743a72dd6fdffa72 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 18 Aug 2021 12:34:18 +0200 Subject: [PATCH] sync: remove DEBUG_LOCKCONTENTION preprocessor directives to allow logging the lock contentions without the need to define DEBUG_LOCKCONTENTION at compile time. --- src/sync.cpp | 5 ----- src/sync.h | 16 +++++----------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/sync.cpp b/src/sync.cpp index ef46bbb22f5..eace86d9dda 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -24,15 +24,10 @@ #include #include -#ifdef DEBUG_LOCKCONTENTION -#if !defined(HAVE_THREAD_LOCAL) -static_assert(false, "thread_local is not supported"); -#endif void LockContention(const char* pszName, const char* pszFile, int nLine) { LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK); } -#endif /* DEBUG_LOCKCONTENTION */ #ifdef DEBUG_LOCKORDER // diff --git a/src/sync.h b/src/sync.h index f4f6ece41dd..bf15c0b4eb4 100644 --- a/src/sync.h +++ b/src/sync.h @@ -126,10 +126,8 @@ using RecursiveMutex = AnnotatedMixin; /** Wrapped mutex: supports waiting but not recursive locking */ typedef AnnotatedMixin Mutex; -#ifdef DEBUG_LOCKCONTENTION /** Prints a lock contention to the log */ void LockContention(const char* pszName, const char* pszFile, int nLine); -#endif /** Wrapper around std::unique_lock style lock for Mutex. */ template @@ -139,22 +137,18 @@ private: void Enter(const char* pszName, const char* pszFile, int nLine) { EnterCritical(pszName, pszFile, nLine, Base::mutex()); -#ifdef DEBUG_LOCKCONTENTION - if (!Base::try_lock()) { - LockContention(pszName, pszFile, nLine); // log the contention -#endif - Base::lock(); -#ifdef DEBUG_LOCKCONTENTION - } -#endif + if (Base::try_lock()) return; + LockContention(pszName, pszFile, nLine); // log the contention + Base::lock(); } bool TryEnter(const char* pszName, const char* pszFile, int nLine) { EnterCritical(pszName, pszFile, nLine, Base::mutex(), true); Base::try_lock(); - if (!Base::owns_lock()) + if (!Base::owns_lock()) { LeaveCritical(); + } return Base::owns_lock(); }