This PR is a follow-up for bitcoin/bitcoin#22778 and bitcoin/bitcoin#24062, and it seems required for bitcoin/bitcoin#24931.
See details in the commit messages.
Could be verified with
$ ./configure CC=clang CXX=clang++ CXXFLAGS='-Wthread-safety -Wthread-safety-negative'
$ make clean
$ make 2>&1 | grep m_most_recent_block_mutex
Could be verified with
$ ./configure CC=clang CXX=clang++ CXXFLAGS='-Wthread-safety -Wthread-safety-negative'
$ make clean
$ make 2>&1 | grep m_tx_relay_mutex
471 | @@ -472,15 +472,16 @@ class PeerManagerImpl final : public PeerManager 472 | EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); 473 | void BlockChecked(const CBlock& block, const BlockValidationState& state) override 474 | EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); 475 | - void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override; 476 | + void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override 477 | + EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex);
I wonder how useful it is to annotate interface functions with member mutexes. The only allowed caller can't see the mutex, as it is private.
An annotation is not for a caller, rather for Clang Thread Safety Analysis C++ extension.
(An external caller (accessing via the virtual/override) can't see the mutex, but an in-class caller could)
Yeah, I was just thinking that it would be incredibly unlikely or even wrong to even have an in-class caller.
lgtm
Concept ACK
ACK 2b3373c1520aa0b41277cd89956224e08cbd79dd