aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorGavin Andresen <[email protected]>2012-01-23 13:15:43 -0500
committerGavin Andresen <[email protected]>2012-01-23 13:15:43 -0500
commita702ceaafca55ab665058eae57c1a5a40921b866 (patch)
treef7b00d314033c21d5eb54608c93e2ae5c2488111 /src/util.cpp
parentMerge branch 'master' of github.com:bitcoin/bitcoin (diff)
parentAdd DEBUG_LOCKCONTENTION, to warn each time a thread waits to lock. (diff)
downloaddiscoin-a702ceaafca55ab665058eae57c1a5a40921b866.tar.xz
discoin-a702ceaafca55ab665058eae57c1a5a40921b866.zip
Merge branch 'lockcontention' of https://github.com/TheBlueMatt/bitcoin
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 67e1bf801..6a4c2a2ef 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -1153,7 +1153,18 @@ static void pop_lock()
void CCriticalSection::Enter(const char* pszName, const char* pszFile, int 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();
+ printf("Locked\n");
+ }
+#else
mutex.lock();
+#endif
}
void CCriticalSection::Leave()
{
@@ -1170,9 +1181,19 @@ bool CCriticalSection::TryEnter(const char* pszName, const char* pszFile, int nL
#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();
+ }
+#else
mutex.lock();
+#endif
}
void CCriticalSection::Leave()