From 3df37e0c78c3d5139c963a74eda56c331355ef72 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Fri, 17 Feb 2023 11:37:56 +0100 Subject: [PATCH 1/2] doc: clarify that LOCK() does AssertLockNotHeld() internally Constructs like ```cpp AssertLockNotHeld(m); LOCK(m); ``` are equivalent to ```cpp LOCK(m); ``` for non-recursive mutexes, so it is ok to omit `AssertLockNotHeld()` in such cases. --- doc/developer-notes.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index e2e54e13d39..d41543ab1c5 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -941,7 +941,9 @@ Threads and synchronization internal to a class (private or protected) rather than public. - Combine annotations in function declarations with run-time asserts in - function definitions: + function definitions (`AssertLockNotHeld()` can be omitted if `LOCK()` is + called unconditionally after it because `LOCK()` does the same check as + `AssertLockNotHeld()` internally, for non-recursive mutexes): ```C++ // txmempool.h From 91d08889218e06631f43a3dab0bae576aa46e43c Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 16 Feb 2023 14:33:57 +0100 Subject: [PATCH 2/2] sync: unpublish LocksHeld() which is used only in sync.cpp --- src/sync.cpp | 2 +- src/sync.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sync.cpp b/src/sync.cpp index 46218056539..58752a9f182 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -246,7 +246,7 @@ void LeaveCritical() pop_lock(); } -std::string LocksHeld() +static std::string LocksHeld() { LockData& lockdata = GetLockData(); std::lock_guard lock(lockdata.dd_mutex); diff --git a/src/sync.h b/src/sync.h index 7242a793abe..09ec0d1255d 100644 --- a/src/sync.h +++ b/src/sync.h @@ -57,7 +57,6 @@ template void EnterCritical(const char* pszName, const char* pszFile, int nLine, MutexType* cs, bool fTry = false); void LeaveCritical(); void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line); -std::string LocksHeld(); template void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(cs); template