-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: Do not discard try_lock()
return value
#26189
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
Microsoft's C++ Standard Library uses the `[[nodiscard]]` attribute for `try_lock()`. See: https://github.com/microsoft/STL/blob/main/stl/inc/mutex This change allows to drop the current suppression for the warning C4838 and helps to prevent the upcoming warning C4858. See: microsoft/STL@539c26c
Friendly ping @ajtowns @ryanofsky @vasild |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
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 bff4e06
The old and new code should have identical behavior. The new code is shorter and silences a warning.
https://en.cppreference.com/w/cpp/thread/unique_lock/try_lock
https://en.cppreference.com/w/cpp/thread/unique_lock/owns_lock
The other call to Base::owns_lock()
can also be avoided:
EnterCritical(pszName, pszFile, nLine, Base::mutex(), true);
if (!Base::try_lock()) {
LeaveCritical();
return false;
}
return true;
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.
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Updated bff4e06 -> 30cc1c6 (pr26189.01 -> pr26189.02, diff):
|
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 30cc1c6
30cc1c6 refactor: Drop `owns_lock()` call (Hennadii Stepanov) bff4e06 refactor: Do not discard `try_lock()` return value (Hennadii Stepanov) Pull request description: Microsoft's C++ Standard Library uses the `[[nodiscard]]` attribute for `try_lock()`. See: https://github.com/microsoft/STL/blob/main/stl/inc/mutex This change allows to drop the current suppression for the warning C4838 and helps to prevent the upcoming warning C4858. See: microsoft/STL@539c26c Fixes bitcoin#26017. Split from bitcoin#25819. ACKs for top commit: vasild: ACK 30cc1c6 Tree-SHA512: ce17404e1c78af4f763129753caf8e5a0e1c91ba398778fe912f9fcc56a847e8112460d1a1a35bf905a593b7d8e0b16c6b099ad74976b67dca5f4f3eda6ff621
f3e40c4 build, msvc: Enable C4834 warning (Hennadii Stepanov) Pull request description: Since bitcoin/bitcoin#26189 our codebase is C4834 warning free. See https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c4834. ACKs for top commit: sipsorcery: tACK f3e40c4. Tree-SHA512: 2dd8fdb5d6c0d4eaf7ffec82039411963010ecea559adfe7e2b5587f467135bd665e0cef5c748e4d6d9ba3c2038d6a5c79980972884adbaaac3bda3b2fbbc408
f3e40c4 build, msvc: Enable C4834 warning (Hennadii Stepanov) Pull request description: Since bitcoin#26189 our codebase is C4834 warning free. See https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c4834. ACKs for top commit: sipsorcery: tACK f3e40c4. Tree-SHA512: 2dd8fdb5d6c0d4eaf7ffec82039411963010ecea559adfe7e2b5587f467135bd665e0cef5c748e4d6d9ba3c2038d6a5c79980972884adbaaac3bda3b2fbbc408
Summary: ``` Microsoft's C++ Standard Library uses the [[nodiscard]] attribute for try_lock(). See: https://github.com/microsoft/STL/blob/main/stl/inc/mutex ``` It appears the same issue occurs with GCC 13.1. Backport of [[bitcoin/bitcoin#26189 | core#26189]]. Test Plan: With debug and GCC 13.1: ninja all check-all It should return no warning. Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Differential Revision: https://reviews.bitcoinabc.org/D14005
Microsoft's C++ Standard Library uses the
[[nodiscard]]
attribute fortry_lock()
.See: https://github.com/microsoft/STL/blob/main/stl/inc/mutex
This change allows to drop the current suppression for the warning C4838 and helps to prevent the upcoming warning C4858.
See: microsoft/STL@539c26c
Fixes #26017.
Split from #25819.