diff --git a/src/script/scriptcache.h b/src/script/scriptcache.h --- a/src/script/scriptcache.h +++ b/src/script/scriptcache.h @@ -8,6 +8,12 @@ #include #include +#include + +// Actually declared in validation.cpp; can't include because of circular +// dependency. +extern RecursiveMutex cs_main; + class CTransaction; /** @@ -48,11 +54,13 @@ * Check if a given key is in the cache, and if so, return its values. * (if not found, nSigChecks may or may not be set to an arbitrary value) */ -bool IsKeyInScriptCache(ScriptCacheKey key, bool erase, int &nSigChecksOut); +bool IsKeyInScriptCache(ScriptCacheKey key, bool erase, int &nSigChecksOut) + EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** * Add an entry in the cache. */ -void AddKeyInScriptCache(ScriptCacheKey key, int nSigChecks); +void AddKeyInScriptCache(ScriptCacheKey key, int nSigChecks) + EXCLUSIVE_LOCKS_REQUIRED(cs_main); #endif // BITCOIN_SCRIPT_SCRIPTCACHE_H diff --git a/src/sync.h b/src/sync.h --- a/src/sync.h +++ b/src/sync.h @@ -56,9 +56,11 @@ std::string LocksHeld(); template void AssertLockHeldInternal(const char *pszName, const char *pszFile, int nLine, - MutexType *cs); + MutexType *cs) EXCLUSIVE_LOCKS_REQUIRED(cs); +template void AssertLockNotHeldInternal(const char *pszName, const char *pszFile, - int nLine, void *cs); + int nLine, MutexType *cs) + EXCLUSIVE_LOCKS_REQUIRED(!cs); void DeleteLock(void *cs); bool LockStackEmpty(); @@ -77,9 +79,12 @@ int line) {} template inline void AssertLockHeldInternal(const char *pszName, const char *pszFile, - int nLine, MutexType *cs) {} -inline void AssertLockNotHeldInternal(const char *pszName, const char *pszFile, - int nLine, void *cs) {} + int nLine, MutexType *cs) + EXCLUSIVE_LOCKS_REQUIRED(cs) {} +template +void AssertLockNotHeldInternal(const char *pszName, const char *pszFile, + int nLine, MutexType *cs) + EXCLUSIVE_LOCKS_REQUIRED(!cs) {} inline void DeleteLock(void *cs) {} inline bool LockStackEmpty() { return true; diff --git a/src/sync.cpp b/src/sync.cpp --- a/src/sync.cpp +++ b/src/sync.cpp @@ -243,8 +243,9 @@ template void AssertLockHeldInternal(const char *, const char *, int, RecursiveMutex *); +template void AssertLockNotHeldInternal(const char *pszName, const char *pszFile, - int nLine, void *cs) { + int nLine, MutexType *cs) { if (!LockHeld(cs)) { return; } @@ -253,6 +254,10 @@ pszName, pszFile, nLine, LocksHeld()); abort(); } +template void AssertLockNotHeldInternal(const char *, const char *, int, + Mutex *); +template void AssertLockNotHeldInternal(const char *, const char *, int, + RecursiveMutex *); void DeleteLock(void *cs) { LockData &lockdata = GetLockData(); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -448,7 +448,7 @@ bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp = nullptr, bool useExistingLockPoints = false) - EXCLUSIVE_LOCKS_REQUIRED(cs_main); + EXCLUSIVE_LOCKS_REQUIRED(::cs_main, pool.cs); /** * Closure representing one script verification. @@ -529,7 +529,8 @@ bool ContextualCheckTransactionForCurrentBlock(const Consensus::Params ¶ms, const CTransaction &tx, TxValidationState &state, - int flags = -1); + int flags = -1) + EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** * Check a block is completely valid from start to finish (only works on top of @@ -929,11 +930,11 @@ /** Mark a block as invalid. */ bool InvalidateBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) - LOCKS_EXCLUDED(cs_main, m_cs_chainstate); + EXCLUSIVE_LOCKS_REQUIRED(!cs_main, !m_cs_chainstate); /** Park a block. */ bool ParkBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) - LOCKS_EXCLUDED(cs_main, m_cs_chainstate); + EXCLUSIVE_LOCKS_REQUIRED(!cs_main, !m_cs_chainstate); /** * Finalize a block. @@ -941,7 +942,7 @@ */ bool FinalizeBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) - LOCKS_EXCLUDED(cs_main, m_cs_chainstate); + EXCLUSIVE_LOCKS_REQUIRED(!cs_main, !m_cs_chainstate); /** Return the currently finalized block index. */ const CBlockIndex *GetFinalizedBlock() const EXCLUSIVE_LOCKS_REQUIRED(cs_main); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1426,7 +1426,7 @@ * deadlock */ void BlockUntilSyncedToCurrentChain() const - LOCKS_EXCLUDED(cs_main, cs_wallet); + EXCLUSIVE_LOCKS_REQUIRED(!::cs_main, !cs_wallet); /** * Set a single wallet flag.