Skip to content

Replace RecursiveMutex cs_addrLocal with Mutex, and rename it - #24108

Merged
maflcko merged 3 commits into
bitcoin:masterfrom
w0xlt:change_cs_addrLocal
Jan 24, 2022
Merged

maflcko merged 3 commits into
bitcoin:masterfrom
w0xlt:change_cs_addrLocal

Conversation

@w0xlt

@w0xlt w0xlt commented Jan 20, 2022

Copy link
Copy Markdown
Contributor

This PR is related to #19303 and gets rid of the RecursiveMutex cs_addrLocal.

-BEGIN VERIFY SCRIPT-
sed -i 's/cs_addrLocal/m_addr_local_mutex/g' -- $(git grep --files-with-matches 'cs_addrLocal')
-END VERIFY SCRIPT-
@DrahtBot DrahtBot added the P2P label Jan 20, 2022

@shaavan shaavan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 63ca568f484a6b36b9485165c4932938f0602b36

  • The new name of cs_addrLocal -> m_addr_local_mutex is an improvement.
  • I checked that m_addr_local_mutex is being used at two places in the codebase. These instances have been addressed by Asserting Lock not held before locking the mutex. So I think it's safe to convert m_addr_local_mutex from RecursiveMutex to Mutex.

@hebasto hebasto left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

Adding AssertLockNotHeld(m_addr_local_mutex) macros should be combined with adding thread safety annotations LOCKS_EXCLUDED(m_addr_local_mutex) in the src/net.h. See https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#threads-and-synchronization

Also, for the safe commit history, "refactor: replace RecursiveMutex m_addr_local_mutex with Mutex" commit should follow "p2p: add assertions for m_addr_local_mutex" one.

@w0xlt
w0xlt force-pushed the change_cs_addrLocal branch from 63ca568 to dec787d Compare January 20, 2022 21:21

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK dec787d, I have reviewed the code and it looks OK, I agree it can be merged.

@shaavan shaavan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK dec787d

Changes since my last review:

  • Added Thread Safety annotation, LOCKS_EXCLUDED(m_addr_local_mutex), to the Get/Set AddrLocal() functions' declaration.
  • Rearranged commits so that m_addr_local_mutex is converted to Mutex, after, other conditions are made right for it.

@maflcko
maflcko merged commit b32f0d3 into bitcoin:master Jan 24, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jan 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants