aboutsummaryrefslogtreecommitdiff
path: root/src/sync.h
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-08-18 12:34:18 +0200
committerJon Atack <jon@atack.com>2021-09-01 15:26:35 +0200
commit7e698732836121912f179b7c743a72dd6fdffa72 (patch)
treed0f5d9b5a1408287b70258aa10218172b758be30 /src/sync.h
parent9b08006bc502e67956d6ab518388fad6397cac8d (diff)
downloadbitcoin-7e698732836121912f179b7c743a72dd6fdffa72.tar.xz
sync: remove DEBUG_LOCKCONTENTION preprocessor directives
to allow logging the lock contentions without the need to define DEBUG_LOCKCONTENTION at compile time.
Diffstat (limited to 'src/sync.h')
-rw-r--r--src/sync.h16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/sync.h b/src/sync.h
index f4f6ece41d..bf15c0b4eb 100644
--- a/src/sync.h
+++ b/src/sync.h
@@ -126,10 +126,8 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
/** Wrapped mutex: supports waiting but not recursive locking */
typedef AnnotatedMixin<std::mutex> 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 <typename Mutex, typename Base = typename Mutex::UniqueLock>
@@ -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();
}