-
Notifications
You must be signed in to change notification settings - Fork 37.8k
refactor: replace RecursiveMutex cs_SubVer
with Mutex (and rename)
#24079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: replace RecursiveMutex cs_SubVer
with Mutex (and rename)
#24079
Conversation
cs SubVer
with Mutex (and rename)cs_SubVer
with Mutex (and rename)
This mutex was added in 22b4966 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. |
-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-
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.
2b92572
to
30927cb
Compare
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 30927cb, I have reviewed the code and it looks OK, I agree it can be merged.
…h Mutex (and rename) 30927cb refactor: replace RecursiveMutex `m_subver_mutex` with Mutex (Sebastian Falbesoner) 0639aba scripted-diff: rename `cs_SubVer` -> `m_subver_mutex` (Sebastian Falbesoner) Pull request description: This PR is related to bitcoin#19303 and gets rid of the RecursiveMutex `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. ACKs for top commit: hebasto: ACK 30927cb, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 2faead792ea0b2f79f9f7fe99acde5cf2bfcd2f15c51fbb6cb1099d4f81276001a492f7d46a5139055f4366c2d58a36a8ba19f21d56df20e0ed93af3141dbe11
This PR is related to #19303 and gets rid of the RecursiveMutex
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.