diff options
author | fanquake <fanquake@gmail.com> | 2022-10-03 18:17:00 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-10-03 18:21:35 +0100 |
commit | 1730f6cb23cc05445df3266cb21b8846b99427b4 (patch) | |
tree | d3d073d08a497f599ed219537100f32050f469a7 | |
parent | b92b12e8f3ea1e318e428e9c2ca0d529fd4452d2 (diff) | |
parent | 30cc1c6609ad7868f73e88afe0b0233d395ec08c (diff) |
Merge bitcoin/bitcoin#26189: refactor: Do not discard `try_lock()` return value
30cc1c6609ad7868f73e88afe0b0233d395ec08c refactor: Drop `owns_lock()` call (Hennadii Stepanov)
bff4e068b69edd40a00466156f860bde2df29268 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: https://github.com/microsoft/STL/commit/539c26c923b38cd0b5eba2bb11de4bea9d5c6e43
Fixes bitcoin/bitcoin#26017.
Split from bitcoin/bitcoin#25819.
ACKs for top commit:
vasild:
ACK 30cc1c6609ad7868f73e88afe0b0233d395ec08c
Tree-SHA512: ce17404e1c78af4f763129753caf8e5a0e1c91ba398778fe912f9fcc56a847e8112460d1a1a35bf905a593b7d8e0b16c6b099ad74976b67dca5f4f3eda6ff621
-rw-r--r-- | src/sync.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/sync.h b/src/sync.h index c34d969041..a9d0091bd2 100644 --- a/src/sync.h +++ b/src/sync.h @@ -165,11 +165,11 @@ private: bool TryEnter(const char* pszName, const char* pszFile, int nLine) { EnterCritical(pszName, pszFile, nLine, Base::mutex(), true); - Base::try_lock(); - if (!Base::owns_lock()) { - LeaveCritical(); + if (Base::try_lock()) { + return true; } - return Base::owns_lock(); + LeaveCritical(); + return false; } public: |