From bff4e068b69edd40a00466156f860bde2df29268 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 10 Aug 2022 23:18:45 +0100 Subject: [PATCH 1/2] refactor: Do not discard `try_lock()` return value 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 --- src/sync.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sync.h b/src/sync.h index c34d969041..a4f4d1ac8d 100644 --- a/src/sync.h +++ b/src/sync.h @@ -165,8 +165,7 @@ 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()) { + if (!Base::try_lock()) { LeaveCritical(); } return Base::owns_lock(); From 30cc1c6609ad7868f73e88afe0b0233d395ec08c Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 3 Oct 2022 12:26:37 +0100 Subject: [PATCH 2/2] refactor: Drop `owns_lock()` call Co-authored-by: Vasil Dimov --- src/sync.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sync.h b/src/sync.h index a4f4d1ac8d..a9d0091bd2 100644 --- a/src/sync.h +++ b/src/sync.h @@ -165,10 +165,11 @@ private: bool TryEnter(const char* pszName, const char* pszFile, int nLine) { EnterCritical(pszName, pszFile, nLine, Base::mutex(), true); - if (!Base::try_lock()) { - LeaveCritical(); + if (Base::try_lock()) { + return true; } - return Base::owns_lock(); + LeaveCritical(); + return false; } public: