This PR is related to #19303 and gets rid of the RecursiveMutex cs_mapLocalHost.
Replace `RecursiveMutex cs_mapLocalHost` with Mutex, and rename it #24099
pull w0xlt wants to merge 2 commits into bitcoin:master from w0xlt:mutex-mapLocalHost changing 4 files +15 −15-
w0xlt commented at 11:44 PM on January 18, 2022: contributor
- DrahtBot added the label P2P on Jan 18, 2022
- DrahtBot added the label RPC/REST/ZMQ on Jan 18, 2022
-
DrahtBot commented at 5:46 AM on January 19, 2022: member
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #20196 (net: fix GetListenPort() to derive the proper port by vasild)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
-
in src/net.cpp:115 in 3e05ab9537 outdated
111 | @@ -112,9 +112,9 @@ static const uint64_t RANDOMIZER_ID_ADDRCACHE = 0x1cf2e4ddd306dda9ULL; // SHA256 112 | // 113 | bool fDiscover = true; 114 | bool fListen = true; 115 | -RecursiveMutex cs_mapLocalHost; 116 | -std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); 117 | -static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {}; 118 | +Mutex map_localhost_mutex;
w0xlt commented at 10:33 AM on January 19, 2022:Thanks for suggestion. Done.
hebasto commented at 7:40 AM on January 19, 2022: memberApproach ACK 3e05ab9537dd4478c66b26f295b63e8081a24bc5.
shaavan commented at 9:21 AM on January 19, 2022: contributorApproach ACK 3e05ab9537dd4478c66b26f295b63e8081a24bc5
Going commit wise:
- The renaming of the mutex
cs_mapLocalHost->map_localhost_mutex, is an improvement, in my opinion. - The type of
map_localhost_mutexis changed from RecursiveMutex to Mutex. I checked through the codebase wheremap_localhost_mutexis used for any instances of recursive lockings, and I found none. Also, I was able to compile this PR without any UB warnings successfully. So I think it’s safe to convert the type of this mutex from RecursiveMutex to Mutex.
I shall ACK this PR as soon as this suggestion by @hebasto is addressed.
a7da1409bcscripted-diff: rename cs_mapLocalHost -> g_maplocalhost_mutex
-BEGIN VERIFY SCRIPT- s() { sed -i 's/cs_mapLocalHost/g_maplocalhost_mutex/g' $1; } s src/net.cpp s src/net.h s src/rpc/net.cpp s src/test/net_tests.cpp -END VERIFY SCRIPT-refactor: replace RecursiveMutex g_maplocalhost_mutex with Mutex 5e7e4c9f6ew0xlt force-pushed on Jan 19, 2022shaavan approvedshaavan commented at 12:05 PM on January 19, 2022: contributorACK 5e7e4c9f6e57f5333bd17a20b0c85a78d032998e
Changes since my last review:
map_localhost_mutex->g_maplocalhost_mutex.
The updated PR compiled successfully on Ubuntu 20.04.
theStack approvedtheStack commented at 4:47 PM on January 19, 2022: memberACK 5e7e4c9f6e57f5333bd17a20b0c85a78d032998e
Checked that within all critical sections that are protected by
g_maplocalhost_mutex, there is no chance another one is called, i.e. a regular Mutex is sufficient.hebasto approvedhebasto commented at 8:59 PM on January 19, 2022: memberACK 5e7e4c9f6e57f5333bd17a20b0c85a78d032998e, I have reviewed the code and it looks OK, I agree it can be merged.
In particular, I've verified that there are no recursive mutex locking on the path
GetLocal()-->CNetAddr::GetReachabilityFrom()-->CNetAddr::IsRoutable().
A script in the "scripted-diff" commit could be more robust:
sed -i 's/cs_mapLocalHost/g_maplocalhost_mutex/g' -- $(git grep --files-with-matches 'cs_mapLocalHost')MarcoFalke merged this on Jan 20, 2022MarcoFalke closed this on Jan 20, 2022sidhujag referenced this in commit e37897e16a on Jan 20, 2022w0xlt deleted the branch on Jan 24, 2022DrahtBot locked this on Jan 24, 2023
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: 2026-04-13 15:14 UTC
More mirrored repositories can be found on mirror.b10c.me