diff options
author | Anthony Towns <aj@erisian.com.au> | 2022-04-20 17:48:14 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2022-05-21 01:23:23 +1000 |
commit | ce893c0497fc9b8ab9752153dfcc77c9f427545e (patch) | |
tree | 9ed8445f0889cb2d4e26a9891d0038d0ced238f7 /doc | |
parent | d2852917eecad6ab422a7b2c9892d351a7f0cc96 (diff) |
doc: Update developer notes
Diffstat (limited to 'doc')
-rw-r--r-- | doc/developer-notes.md | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/doc/developer-notes.md b/doc/developer-notes.md index ddbbd0709b..ea08c4f1a8 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -902,14 +902,19 @@ Threads and synchronization - Prefer `Mutex` type to `RecursiveMutex` one. - Consistently use [Clang Thread Safety Analysis](https://clang.llvm.org/docs/ThreadSafetyAnalysis.html) annotations to - get compile-time warnings about potential race conditions in code. Combine annotations in function declarations with - run-time asserts in function definitions: + get compile-time warnings about potential race conditions or deadlocks in code. - In functions that are declared separately from where they are defined, the thread safety annotations should be added exclusively to the function declaration. Annotations on the definition could lead to false positives (lack of compile failure) at call sites between the two. + - Prefer locks that are in a class rather than global, and that are + internal to a class (private or protected) rather than public. + + - Combine annotations in function declarations with run-time asserts in + function definitions: + ```C++ // txmempool.h class CTxMemPool @@ -933,21 +938,37 @@ void CTxMemPool::UpdateTransactionsFromBlock(...) ```C++ // validation.h -class ChainstateManager +class CChainState { +protected: + ... + Mutex m_chainstate_mutex; + ... public: ... - bool ProcessNewBlock(...) LOCKS_EXCLUDED(::cs_main); + bool ActivateBestChain( + BlockValidationState& state, + std::shared_ptr<const CBlock> pblock = nullptr) + EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex) + LOCKS_EXCLUDED(::cs_main); + ... + bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex) + EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex) + LOCKS_EXCLUDED(::cs_main); ... } // validation.cpp -bool ChainstateManager::ProcessNewBlock(...) +bool CChainState::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex) { + AssertLockNotHeld(m_chainstate_mutex); AssertLockNotHeld(::cs_main); - ... - LOCK(::cs_main); - ... + { + LOCK(cs_main); + ... + } + + return ActivateBestChain(state, std::shared_ptr<const CBlock>()); } ``` |