mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
doc: Update developer notes
This commit is contained in:
parent
d2852917ee
commit
ce893c0497
1 changed files with 29 additions and 8 deletions
|
@ -902,14 +902,19 @@ Threads and synchronization
|
||||||
- Prefer `Mutex` type to `RecursiveMutex` one.
|
- Prefer `Mutex` type to `RecursiveMutex` one.
|
||||||
|
|
||||||
- Consistently use [Clang Thread Safety Analysis](https://clang.llvm.org/docs/ThreadSafetyAnalysis.html) annotations to
|
- 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
|
get compile-time warnings about potential race conditions or deadlocks in code.
|
||||||
run-time asserts in function definitions:
|
|
||||||
|
|
||||||
- In functions that are declared separately from where they are defined, the
|
- In functions that are declared separately from where they are defined, the
|
||||||
thread safety annotations should be added exclusively to the function
|
thread safety annotations should be added exclusively to the function
|
||||||
declaration. Annotations on the definition could lead to false positives
|
declaration. Annotations on the definition could lead to false positives
|
||||||
(lack of compile failure) at call sites between the two.
|
(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++
|
```C++
|
||||||
// txmempool.h
|
// txmempool.h
|
||||||
class CTxMemPool
|
class CTxMemPool
|
||||||
|
@ -933,21 +938,37 @@ void CTxMemPool::UpdateTransactionsFromBlock(...)
|
||||||
|
|
||||||
```C++
|
```C++
|
||||||
// validation.h
|
// validation.h
|
||||||
class ChainstateManager
|
class CChainState
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
...
|
||||||
|
Mutex m_chainstate_mutex;
|
||||||
|
...
|
||||||
public:
|
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
|
// validation.cpp
|
||||||
bool ChainstateManager::ProcessNewBlock(...)
|
bool CChainState::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
|
||||||
{
|
{
|
||||||
|
AssertLockNotHeld(m_chainstate_mutex);
|
||||||
AssertLockNotHeld(::cs_main);
|
AssertLockNotHeld(::cs_main);
|
||||||
...
|
{
|
||||||
LOCK(::cs_main);
|
LOCK(cs_main);
|
||||||
...
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActivateBestChain(state, std::shared_ptr<const CBlock>());
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue