mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 19:23:26 -03:00
test: Add LockStackEmpty()
This commit is contained in:
parent
42b2a95373
commit
63e9e40b73
3 changed files with 21 additions and 6 deletions
11
src/sync.cpp
11
src/sync.cpp
|
@ -264,6 +264,17 @@ void DeleteLock(void* cs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LockStackEmpty()
|
||||||
|
{
|
||||||
|
LockData& lockdata = GetLockData();
|
||||||
|
std::lock_guard<std::mutex> lock(lockdata.dd_mutex);
|
||||||
|
const auto it = lockdata.m_lock_stacks.find(std::this_thread::get_id());
|
||||||
|
if (it == lockdata.m_lock_stacks.end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return it->second.empty();
|
||||||
|
}
|
||||||
|
|
||||||
bool g_debug_lockorder_abort = true;
|
bool g_debug_lockorder_abort = true;
|
||||||
|
|
||||||
#endif /* DEBUG_LOCKORDER */
|
#endif /* DEBUG_LOCKORDER */
|
||||||
|
|
14
src/sync.h
14
src/sync.h
|
@ -56,6 +56,7 @@ template <typename MutexType>
|
||||||
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) ASSERT_EXCLUSIVE_LOCK(cs);
|
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) ASSERT_EXCLUSIVE_LOCK(cs);
|
||||||
void AssertLockNotHeldInternal(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);
|
void DeleteLock(void* cs);
|
||||||
|
bool LockStackEmpty();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call abort() if a potential lock order deadlock bug is detected, instead of
|
* Call abort() if a potential lock order deadlock bug is detected, instead of
|
||||||
|
@ -64,13 +65,14 @@ void DeleteLock(void* cs);
|
||||||
*/
|
*/
|
||||||
extern bool g_debug_lockorder_abort;
|
extern bool g_debug_lockorder_abort;
|
||||||
#else
|
#else
|
||||||
void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {}
|
inline void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {}
|
||||||
void static inline LeaveCritical() {}
|
inline void LeaveCritical() {}
|
||||||
void static inline CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line) {}
|
inline void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line) {}
|
||||||
template <typename MutexType>
|
template <typename MutexType>
|
||||||
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) ASSERT_EXCLUSIVE_LOCK(cs) {}
|
inline void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) ASSERT_EXCLUSIVE_LOCK(cs) {}
|
||||||
void static inline AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
|
inline void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
|
||||||
void static inline DeleteLock(void* cs) {}
|
inline void DeleteLock(void* cs) {}
|
||||||
|
inline bool LockStackEmpty() { return true; }
|
||||||
#endif
|
#endif
|
||||||
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
|
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
|
||||||
#define AssertLockNotHeld(cs) AssertLockNotHeldInternal(#cs, __FILE__, __LINE__, &cs)
|
#define AssertLockNotHeld(cs) AssertLockNotHeldInternal(#cs, __FILE__, __LINE__, &cs)
|
||||||
|
|
|
@ -14,6 +14,7 @@ void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
|
||||||
{
|
{
|
||||||
LOCK2(mutex1, mutex2);
|
LOCK2(mutex1, mutex2);
|
||||||
}
|
}
|
||||||
|
BOOST_CHECK(LockStackEmpty());
|
||||||
bool error_thrown = false;
|
bool error_thrown = false;
|
||||||
try {
|
try {
|
||||||
LOCK2(mutex2, mutex1);
|
LOCK2(mutex2, mutex1);
|
||||||
|
@ -21,6 +22,7 @@ void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
|
||||||
BOOST_CHECK_EQUAL(e.what(), "potential deadlock detected: mutex1 -> mutex2 -> mutex1");
|
BOOST_CHECK_EQUAL(e.what(), "potential deadlock detected: mutex1 -> mutex2 -> mutex1");
|
||||||
error_thrown = true;
|
error_thrown = true;
|
||||||
}
|
}
|
||||||
|
BOOST_CHECK(LockStackEmpty());
|
||||||
#ifdef DEBUG_LOCKORDER
|
#ifdef DEBUG_LOCKORDER
|
||||||
BOOST_CHECK(error_thrown);
|
BOOST_CHECK(error_thrown);
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Add table
Reference in a new issue