Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Jun 10, 2020

This PR replaces RecursiveMutex CAddrMan::cs with Mutex CAddrMan::cs.

All of the related code branches are covered by appropriate lock assertions to insure that the mutex locking policy has not been changed by accident.

Related to #19303.

Based on #22025, and first three commits belong to it.

@hebasto
Copy link
Member Author

hebasto commented Jun 10, 2020

cc @vasild :)

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 10, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@maflcko
Copy link
Member

maflcko commented Jun 10, 2020

Concept ACK. I think the reason that LOCKS_EXCLUDED isn't widely used in the code base is that it doesn't propagate up the call stack, so has a rather limited use case. Though, the new syntax claims to do that.

@maflcko maflcko removed the Tests label Jun 10, 2020
@maflcko
Copy link
Member

maflcko commented Jun 10, 2020

oh wait you are not adding the annotations. Any reason for that?

@hebasto
Copy link
Member Author

hebasto commented Jun 10, 2020

@MarcoFalke

oh wait you are not adding the annotations. Any reason for that?

Added :)

@hebasto
Copy link
Member Author

hebasto commented Jun 10, 2020

@MarcoFalke probably a1071f8 deserves its own PR as it blocks the similar changes in other parts of the code, right?

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

Looks good, some suggestions below.

The last two commits:

Add means to handle negative capabilities in thread safety annotations
refactor: Add negative thread safety annotations to CAddrMan

are somewhat unrelated and maybe deserve a separate PR if they cause some controversy or if another reviewer asks to move them away to ease review. Since I already reviewed everything I am fine with them as they are.

@hebasto
Copy link
Member Author

hebasto commented Jun 11, 2020

Updated d957293 -> b6712ec (pr19238.02 -> pr19238.04):

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK b6712ec

maflcko pushed a commit that referenced this pull request Jun 17, 2020
…Thread Safety annotations

f8213c0 Add means to handle negative capabilities in thread safety annotations (Hennadii Stepanov)

Pull request description:

  This commit is separated from #19238, and it adds support of [Negative Capabilities](https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#negative) in the Clang Thread Safety Analysis attributes.

  > Negative requirements are an alternative `EXCLUDES` [`LOCKS_EXCLUDED`] that provide a stronger safety guarantee. A negative requirement uses the `REQUIRES` [`EXCLUSIVE_LOCKS_REQUIRED`] attribute, in conjunction with the ! operator, to indicate that a capability should not be held.

  Examples of usage:
  - #19238 (for a class)
  - https://github.com/hebasto/bitcoin/tree/200610-addrman-tsn (for the whole code base)

ACKs for top commit:
  MarcoFalke:
    Approach ACK f8213c0
  vasild:
    ACK f8213c0

Tree-SHA512: 86d992826b87579661bd228712ae5ee6acca6f70b885ef7e96458974eac184e4874a525c669607ba6b6c861aa4806409a8792d100e6914c858bcab43d31cfb1b
@hebasto hebasto force-pushed the 200610-addrman-mx branch from b6712ec to 9cd0ed8 Compare June 17, 2020 11:21
@hebasto
Copy link
Member Author

hebasto commented Jun 17, 2020

Updated b6712ec -> 9cd0ed8 (pr19238.04 -> pr19238.05):

@hebasto
Copy link
Member Author

hebasto commented Jun 17, 2020

The OP has been updated.

@hebasto
Copy link
Member Author

hebasto commented Jun 18, 2020

@sipa Mind reviewing this PR?

@hebasto
Copy link
Member Author

hebasto commented Jun 18, 2020

btw, how about convention to add the _cs suffix to the name of the function that is called from within the critical section already guarded by the locked instance of the Mutex?

@vasild
Copy link
Contributor

vasild commented Jun 18, 2020

btw, how about convention to add the _cs suffix to the name of the function that is called from within the critical section already guarded by the locked instance of the Mutex?

I like it, and it is shorter than ...NonLockHelper(), but what about the CamelCaseConvention? Also, it would get fuzzy if more than one mutex is involved and a method requires one to be held and the other not...

@hebasto hebasto force-pushed the 200610-addrman-mx branch from ee79105 to e2787fb Compare May 27, 2021 14:12
@hebasto
Copy link
Member Author

hebasto commented May 27, 2021

Rebased ee79105 -> e2787fb (pr19238.10 -> pr19238.11) due to the merging of #22025.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK e2787fb

@hebasto
Copy link
Member Author

hebasto commented Jun 12, 2021

Rebased e2787fb -> af95505 (pr19238.11 -> pr19238.12) due to the conflict with #18722.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK af95505

@jnewbery
Copy link
Contributor

Code review ACK af95505

@maflcko
Copy link
Member

maflcko commented Jun 14, 2021

There might be a silent merge conflict

@maflcko
Copy link
Member

maflcko commented Jun 14, 2021

test/fuzz/addrman.cpp:110:30: error: 'Check' is a private member of 'CAddrMan'
    (void)/*const_*/addr_man.Check();
                             ^
./addrman.h:722:10: note: declared private here
    void Check()
         ^
1 error generated.

hebasto and others added 2 commits June 14, 2021 17:21
The unit test is single threaded, so there's no need to hold the mutex
between Good() and Attempt().

This change avoids recursive locking in the CAddrMan::Attempt function.

Co-authored-by: John Newbery <john@johnnewbery.com>
@hebasto
Copy link
Member Author

hebasto commented Jun 14, 2021

There might be a silent merge conflict

With #21941. Rebasing.

@hebasto hebasto force-pushed the 200610-addrman-mx branch from af95505 to ae98aec Compare June 14, 2021 14:29
@hebasto
Copy link
Member Author

hebasto commented Jun 14, 2021

@MarcoFalke @jnewbery @vasild

Rebased af95505 -> ae98aec (pr19238.12 -> pr19238.13) due to the silent merge conflict with #21941.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK ae98aec

@maflcko maflcko merged commit 3a2c84a into bitcoin:master Jun 14, 2021
@hebasto hebasto deleted the 200610-addrman-mx branch June 14, 2021 15:03
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 14, 2021
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants