Add DEBUG_LOCKCONTENTION, to warn each time a thread waits to lock.
If compiled with -DDEBUG_LOCKCONTENTION, Bitcoin will print to debug.log each time a thread has to wait for a lock to continue.
This commit is contained in:
parent
1240a1b0a8
commit
198fb229a4
1 changed files with 22 additions and 1 deletions
23
src/util.cpp
23
src/util.cpp
|
@ -1153,7 +1153,18 @@ static void pop_lock()
|
||||||
void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine)
|
void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine)
|
||||||
{
|
{
|
||||||
push_lock(this, CLockLocation(pszName, pszFile, nLine));
|
push_lock(this, CLockLocation(pszName, pszFile, nLine));
|
||||||
|
#ifdef DEBUG_LOCKCONTENTION
|
||||||
|
bool result = mutex.try_lock();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
printf("LOCKCONTENTION: %s\n", pszName);
|
||||||
|
printf("Locker: %s:%d\n", pszFile, nLine);
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
printf("Locked\n");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
mutex.lock();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
void CCriticalSection::Leave()
|
void CCriticalSection::Leave()
|
||||||
{
|
{
|
||||||
|
@ -1170,10 +1181,20 @@ bool CCriticalSection::TryEnter(const char* pszName, const char* pszFile, int nL
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void CCriticalSection::Enter(const char*, const char*, int)
|
void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_LOCKCONTENTION
|
||||||
|
bool result = mutex.try_lock();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
printf("LOCKCONTENTION: %s\n", pszName);
|
||||||
|
printf("Locker: %s:%d\n", pszFile, nLine);
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
mutex.lock();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void CCriticalSection::Leave()
|
void CCriticalSection::Leave()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue