mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
sync: remove DEBUG_LOCKCONTENTION preprocessor directives
to allow logging the lock contentions without the need to define DEBUG_LOCKCONTENTION at compile time.
This commit is contained in:
@@ -24,15 +24,10 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#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)
|
void LockContention(const char* pszName, const char* pszFile, int nLine)
|
||||||
{
|
{
|
||||||
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
|
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
|
||||||
}
|
}
|
||||||
#endif /* DEBUG_LOCKCONTENTION */
|
|
||||||
|
|
||||||
#ifdef DEBUG_LOCKORDER
|
#ifdef DEBUG_LOCKORDER
|
||||||
//
|
//
|
||||||
|
|||||||
16
src/sync.h
16
src/sync.h
@@ -126,10 +126,8 @@ 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;
|
||||||
|
|
||||||
#ifdef DEBUG_LOCKCONTENTION
|
|
||||||
/** Prints a lock contention to the log */
|
/** Prints a lock contention to the log */
|
||||||
void LockContention(const char* pszName, const char* pszFile, int nLine);
|
void LockContention(const char* pszName, const char* pszFile, int nLine);
|
||||||
#endif
|
|
||||||
|
|
||||||
/** 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>
|
||||||
@@ -139,22 +137,18 @@ private:
|
|||||||
void Enter(const char* pszName, const char* pszFile, int nLine)
|
void Enter(const char* pszName, const char* pszFile, int nLine)
|
||||||
{
|
{
|
||||||
EnterCritical(pszName, pszFile, nLine, Base::mutex());
|
EnterCritical(pszName, pszFile, nLine, Base::mutex());
|
||||||
#ifdef DEBUG_LOCKCONTENTION
|
if (Base::try_lock()) return;
|
||||||
if (!Base::try_lock()) {
|
LockContention(pszName, pszFile, nLine); // log the contention
|
||||||
LockContention(pszName, pszFile, nLine); // log the contention
|
Base::lock();
|
||||||
#endif
|
|
||||||
Base::lock();
|
|
||||||
#ifdef DEBUG_LOCKCONTENTION
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TryEnter(const char* pszName, const char* pszFile, int nLine)
|
bool TryEnter(const char* pszName, const char* pszFile, int nLine)
|
||||||
{
|
{
|
||||||
EnterCritical(pszName, pszFile, nLine, Base::mutex(), true);
|
EnterCritical(pszName, pszFile, nLine, Base::mutex(), true);
|
||||||
Base::try_lock();
|
Base::try_lock();
|
||||||
if (!Base::owns_lock())
|
if (!Base::owns_lock()) {
|
||||||
LeaveCritical();
|
LeaveCritical();
|
||||||
|
}
|
||||||
return Base::owns_lock();
|
return Base::owns_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user