cs_SubVer
. Both of the critical sections only directly access the guarded variable, i.e. it is not possible that within one section another one is called, and we can use a regular Mutex.
refactor: replace RecursiveMutex cs_SubVer
with Mutex (and rename)
#24079
pull
theStack
wants to merge
2
commits into
bitcoin:master
from
theStack:202201-refactor_replace_RecursiveMutex_cs_subver
changing
3
files
+4 −4
-
theStack commented at 1:44 am on January 16, 2022: memberThis PR is related to #19303 and gets rid of the RecursiveMutex
-
theStack renamed this:
refactor: replace RecursiveMutex `cs SubVer` with Mutex (and rename)
refactor: replace RecursiveMutex `cs_SubVer` with Mutex (and rename)
on Jan 16, 2022 -
DrahtBot added the label P2P on Jan 16, 2022
-
DrahtBot added the label Refactoring on Jan 16, 2022
-
in src/net.h:437 in 2b92572d0e outdated
433@@ -434,12 +434,12 @@ class CNode 434 //! Whether this peer is an inbound onion, i.e. connected via our Tor onion service. 435 const bool m_inbound_onion; 436 std::atomic<int> nVersion{0}; 437- RecursiveMutex cs_SubVer; 438+ Mutex subver_mutex;
hebasto commented at 8:33 am on January 16, 2022:0 Mutex m_subver_mutex;
theStack commented at 3:54 pm on January 16, 2022:Thanks, done.hebasto commented at 8:59 am on January 16, 2022: memberThis mutex was added in 22b4966a29501c4f3f2e970ac5008fbd91e665a9 back in 2017.
Maybe it is out of this PR scope, but in the current codebase I see no reasons for it because a write operation is executed once only during processing the received VERSION message.
scripted-diff: rename `cs_SubVer` -> `m_subver_mutex`
-BEGIN VERIFY SCRIPT- sed -i 's/cs_SubVer/m_subver_mutex/g' ./src/net.h ./src/net.cpp ./src/net_processing.cpp -END VERIFY SCRIPT-
refactor: replace RecursiveMutex `m_subver_mutex` with Mutex
In each of the critical sections, only the the guarded variable is accessed, without any chance that within one section another one is called. Hence, we can use an ordinary Mutex instead of RecursiveMutex.
theStack force-pushed on Jan 16, 2022theStack commented at 3:59 pm on January 16, 2022: memberMaybe it is out of this PR scope, but in the current codebase I see no reasons for it because a write operation is executed once only during processing the received VERSION message.
I agree that it’s unlikely, but isn’t there still a non-zero probability that access could happen concurrently? Processing of a VERSION message could in theory happen during a getpeerinfo RPC call – a peer is already in the nodes list before the version exchange is completed.
hebasto approvedhebasto commented at 4:07 pm on January 16, 2022: memberACK 30927cb5306d01da2716786c2d9457c49ec49d0f, I have reviewed the code and it looks OK, I agree it can be merged.MarcoFalke merged this on Jan 17, 2022MarcoFalke closed this on Jan 17, 2022
theStack deleted the branch on Jan 17, 2022sidhujag referenced this in commit 2ec7929b1c on Jan 18, 2022DrahtBot locked this on Jan 17, 2023Labels
Refactoring P2P
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 18:12 UTC
More mirrored repositories can be found on mirror.b10c.me