HomePhabricator

refactor: various RecursiveMutex replacements in CConnman

Description

refactor: various RecursiveMutex replacements in CConnman

Summary:

The RecursiveMutex cs_totalBytesRecv is only used at two places: in
CConnman::RecordBytesRecv() to increment the nTotalBytesRecv member, and in
CConnman::GetTotalBytesRecv() to read it. For this simple use-case, we can
make the member std::atomic instead to achieve the same result.

https://github.com/bitcoin/bitcoin/pull/22829/commits/574cc4271ab09a4c8f8d076cb1a3a2d5b3924b73


The RecursiveMutex m_addr_fetches_mutex is used at three places:

  • CConnman::AddAddrFetch()
  • CConnman::ProcessAddrFetch()
  • CConnman::ThreadOpenConnections()

In each of the critical sections, only the the m_addr_fetches is accessed
(and in the last case, also vAddedNodes), without any chance that within
one section another one is called. Hence, we can use an ordinary Mutex
instead of RecursiveMutex.

https://github.com/bitcoin/bitcoin/pull/22829/commits/7d52ff5c389643cde613d86fee33d7087f47b8b4


The RecursiveMutex m_added_nodes_mutex is used at three places:

  • CConnman::GetAddedNodeInfo()
  • CConnman::AddNode()
  • CConnman::ThreadOpenConnections()

In each of the critical sections, only the the m_added_nodes member is
accessed (and in the last case, also m_addr_fetches), without any chance
that within one section another one is called. Hence, we can use an
ordinary Mutex instead of RecursiveMutex.

https://github.com/bitcoin/bitcoin/pull/22829/commits/3726a4595837b66d37f151faf1cec2796d6b74d7


This concludes backport of core#22829

Test Plan:
With Debug and TSAN:
ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13355

Details

Provenance
Sebastian Falbesoner <sebastian.falbesoner@gmail.com>Authored on Aug 28 2021, 17:51
PiRKCommitted on Mar 16 2023, 17:25
PiRKPushed on Mar 16 2023, 17:25
Reviewer
Restricted Project
Differential Revision
D13355: refactor: various RecursiveMutex replacements in CConnman
Parents
rABC71d279e846aa: scripted-diff: rename node vector/mutex members in CConnman
Branches
Unknown
Tags
Unknown