Skip to content
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

Replace RecursiveMutex cs_addrLocal with Mutex, and rename it #24108

Merged
merged 3 commits into from
Jan 24, 2022

Conversation

w0xlt
Copy link
Contributor

@w0xlt w0xlt commented Jan 20, 2022

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
Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

ACK 63ca568

  • 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.

Copy link
Member

@hebasto hebasto left a comment

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
Copy link
Member

@hebasto hebasto left a comment

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.

Copy link
Contributor

@shaavan shaavan left a comment

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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 28, 2022
…, and rename it

dec787d refactor: replace RecursiveMutex `m_addr_local_mutex` with Mutex (w0xlt)
93609c1 p2p: add assertions and negative TS annotations for m_addr_local_mutex (w0xlt)
c4a31ca scripted-diff: rename cs_addrLocal -> m_addr_local_mutex (w0xlt)

Pull request description:

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

ACKs for top commit:
  hebasto:
    ACK dec787d, I have reviewed the code and it looks OK, I agree it can be merged.
  shaavan:
    reACK dec787d

Tree-SHA512: b7a043bfd4e2ccbe313bff21ad815169db6ad215ca96daf358ce960c496a548b4a9e90be9e4357430ca59652b96df87c097450118996c6d4703cbaabde2072d0
@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