Page MenuHomePhabricator

refactor: various RecursiveMutex replacements in CConnman
ClosedPublic

Authored by PiRK on Mar 16 2023, 16:14.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCdc3c7747e18c: 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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable