diff --git a/src/sync.h b/src/sync.h --- a/src/sync.h +++ b/src/sync.h @@ -297,4 +297,16 @@ operator bool() const { return fHaveGrant; } }; +// Utility class for indicating to compiler thread analysis that a mutex is +// locked (when it couldn't be determined otherwise). +struct SCOPED_LOCKABLE LockAnnotation { + template + explicit LockAnnotation(Mutex &mutex) EXCLUSIVE_LOCK_FUNCTION(mutex) { +#ifdef DEBUG_LOCKORDER + AssertLockHeld(mutex); +#endif + } + ~LockAnnotation() UNLOCK_FUNCTION() {} +}; + #endif // BITCOIN_SYNC_H diff --git a/src/threadsafety.h b/src/threadsafety.h --- a/src/threadsafety.h +++ b/src/threadsafety.h @@ -61,12 +61,4 @@ #define ASSERT_EXCLUSIVE_LOCK(...) #endif // __GNUC__ -// Utility class for indicating to compiler thread analysis that a mutex is -// locked (when it couldn't be determined otherwise). -struct SCOPED_LOCKABLE LockAnnotation { - template - explicit LockAnnotation(Mutex &mutex) EXCLUSIVE_LOCK_FUNCTION(mutex) {} - ~LockAnnotation() UNLOCK_FUNCTION() {} -}; - #endif // BITCOIN_THREADSAFETY_H diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -296,8 +296,8 @@ SetMockTime(mockTime); CBlockIndex *block = nullptr; if (blockTime > 0) { - LockAnnotation lock(::cs_main); auto locked_chain = wallet.chain().lock(); + LockAnnotation lock(::cs_main); auto inserted = mapBlockIndex.emplace(BlockHash(GetRandHash()), new CBlockIndex); assert(inserted.second);