-
Notifications
You must be signed in to change notification settings - Fork 37.7k
threading: remove ancient CRITICAL_SECTION macros #32592
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32592. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
As mentioned in the description, failing tests are just demonstrating the borked REVERSE_LOCK fixed by #32465. |
Concept ACK. |
Concept ACK |
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.
Pushed a small additional commit that removes a now-unnecessary template instantiation. Just a little janitorial work, but it will make some future changes more obviously correct. |
https://cirrus-ci.com/task/6734127736553472?logs=ci#L3223 [12:12:21.305] /ci_container_base/src/test/reverselock_tests.cpp:23:9: error: cannot call function 'AssertLockNotHeldInline' while mutex 'mutex' is held [-Werror,-Wthread-safety-analysis]
[12:12:21.305] 23 | AssertLockNotHeld(mutex);
[12:12:21.305] | ^
[12:12:21.305] /ci_container_base/src/sync.h:141:31: note: expanded from macro 'AssertLockNotHeld'
[12:12:21.305] 141 | #define AssertLockNotHeld(cs) AssertLockNotHeldInline(#cs, __FILE__, __LINE__, &cs)
[12:12:21.305] | ^
[12:12:21.305] 1 error generated. |
As expected :) From description:
|
Put this on |
This is tagged for 30.0, but feature freeze is in less than two weeks, and it still needs rebase, so it'll likely miss the milestone. |
Feature freeze doesn't seem important here, given this isn't a feature; it's part of a cleanup of which the prior PRs have already landed, so landing this any time before branch off seems fine (assuming it gets rebased, have pinged @theuni). |
No functional change.
These were only required for the ENTER_CRITICAL_SECTION macro.
2d40a45
to
46ca771
Compare
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 46ca771
@@ -704,7 +704,7 @@ static RPCHelpMan getblocktemplate() | |||
NodeContext& node = EnsureAnyNodeContext(request.context); | |||
ChainstateManager& chainman = EnsureChainman(node); | |||
Mining& miner = EnsureMining(node); | |||
LOCK(cs_main); | |||
WAIT_LOCK(cs_main, csmain_lock); |
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.
Not really related to this PR, but I really don't like how long the scope of the lock is here. We could reduce this a bit by doing something like
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index b710c605bc..750ca72bb4 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -707,2 +706,0 @@ static RPCHelpMan getblocktemplate()
- WAIT_LOCK(cs_main, csmain_lock);
- uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash};
@@ -737,0 +736 @@ static RPCHelpMan getblocktemplate()
+ LOCK(cs_main);
@@ -775,0 +775,3 @@ static RPCHelpMan getblocktemplate()
+ WAIT_LOCK(cs_main, cs_main_lock);
+ uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash};
+
@@ -814 +816 @@ static RPCHelpMan getblocktemplate()
- REVERSE_LOCK(csmain_lock, cs_main);
+ REVERSE_LOCK(cs_main_lock, cs_main);
but then going on to hold it through the entire marshalling block also does not seem ideal.
review ACK 46ca771 📌 Show signatureSignature:
|
Code review ACK 46ca771 |
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 46ca771
Now that #32467 is merged, the only remaining usage of our old
CRITICAL_SECTION
macros (other than tests) is ingetblocktemplate()
and it can safely be replaced with aREVERSE_LOCK
.This PR makes that replacement, replaces the old
CRITICAL_SECTION
macro usage in tests, then deletes the macros themselves.While testing this a few weeks ago, I noticed thatREVERSE_LOCK
does not currently work properly with our thread-safety annotations as after theREVERSE_LOCK
is acquired, clang still believes that the mutex is locked. #32465 fixes this problem. Without that fix, this PR would potentially allow a false-negative if code were added in the future to this chunk ofgetblocktemplate
which requiredcs_main
to be locked.I added a test for the reverse lock here in the form of a compiler warning inreverselock_tests.cpp
to simulate that possibility. This PR will therefore cause a new warning (and should fail a warnings-as-errors ci check) until #32465 is merged and this is rebased on top of it.Edit: Rebased on top of #32465, so this should now pass tests.