aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2017-01-17 17:42:46 -0500
committerMatt Corallo <git@bluematt.me>2017-10-13 19:29:54 -0400
commit2b4b34503ff0ed44365d83a68ffed2736ea9cc51 (patch)
tree62462c66263e297f19d6b1de7a24f91acfab8093 /src
parent0343676ce32ef69b25bada101223b92f92da158a (diff)
downloadbitcoin-2b4b34503ff0ed44365d83a68ffed2736ea9cc51.tar.xz
Add ability to assert a lock is not held in DEBUG_LOCKORDER
Diffstat (limited to 'src')
-rw-r--r--src/sync.cpp10
-rw-r--r--src/sync.h3
2 files changed, 13 insertions, 0 deletions
diff --git a/src/sync.cpp b/src/sync.cpp
index 87024ccdf2..4ef419cd09 100644
--- a/src/sync.cpp
+++ b/src/sync.cpp
@@ -155,6 +155,16 @@ void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine,
abort();
}
+void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
+{
+ for (const std::pair<void*, CLockLocation>& i : *lockstack) {
+ if (i.first == cs) {
+ fprintf(stderr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
+ abort();
+ }
+ }
+}
+
void DeleteLock(void* cs)
{
if (!lockdata.available) {
diff --git a/src/sync.h b/src/sync.h
index 0871c5fb4d..2790fc6f23 100644
--- a/src/sync.h
+++ b/src/sync.h
@@ -75,14 +75,17 @@ void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs
void LeaveCritical();
std::string LocksHeld();
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs);
+void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs);
void DeleteLock(void* cs);
#else
void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {}
void static inline LeaveCritical() {}
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
+void static inline AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
void static inline DeleteLock(void* cs) {}
#endif
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
+#define AssertLockNotHeld(cs) AssertLockNotHeldInternal(#cs, __FILE__, __LINE__, &cs)
/**
* Wrapped boost mutex: supports recursive locking, but no waiting