Skip to content

Commit 2ee7743

Browse files
ajtownshebasto
authored andcommitted
sync.h: Make runtime lock checks require compile-time lock checks
1 parent 23d71d1 commit 2ee7743

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/sync.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,15 @@ void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine,
238238
template void AssertLockHeldInternal(const char*, const char*, int, Mutex*);
239239
template void AssertLockHeldInternal(const char*, const char*, int, RecursiveMutex*);
240240

241-
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
241+
template <typename MutexType>
242+
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs)
242243
{
243244
if (!LockHeld(cs)) return;
244245
tfm::format(std::cerr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld());
245246
abort();
246247
}
248+
template void AssertLockNotHeldInternal(const char*, const char*, int, Mutex*);
249+
template void AssertLockNotHeldInternal(const char*, const char*, int, RecursiveMutex*);
247250

248251
void DeleteLock(void* cs)
249252
{

src/sync.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ void LeaveCritical();
5353
void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line);
5454
std::string LocksHeld();
5555
template <typename MutexType>
56-
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs);
57-
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs);
56+
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(cs);
57+
template <typename MutexType>
58+
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs);
5859
void DeleteLock(void* cs);
5960
bool LockStackEmpty();
6061

@@ -69,8 +70,9 @@ inline void EnterCritical(const char* pszName, const char* pszFile, int nLine, v
6970
inline void LeaveCritical() {}
7071
inline void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line) {}
7172
template <typename MutexType>
72-
inline void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) {}
73-
inline void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
73+
inline void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(cs) {}
74+
template <typename MutexType>
75+
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) {}
7476
inline void DeleteLock(void* cs) {}
7577
inline bool LockStackEmpty() { return true; }
7678
#endif

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ bool TestLockPointValidity(const LockPoints* lp) EXCLUSIVE_LOCKS_REQUIRED(cs_mai
245245
*
246246
* See consensus/consensus.h for flag definitions.
247247
*/
248-
bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
248+
bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, pool.cs);
249249

250250
/**
251251
* Closure representing one script verification

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
11791179
* Obviously holding cs_main/cs_wallet when going into this call may cause
11801180
* deadlock
11811181
*/
1182-
void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(cs_main, cs_wallet);
1182+
void BlockUntilSyncedToCurrentChain() const EXCLUSIVE_LOCKS_REQUIRED(!::cs_main, !cs_wallet);
11831183

11841184
/** set a single wallet flag */
11851185
void SetWalletFlag(uint64_t flags);

0 commit comments

Comments
 (0)