From 36dee459caf498edf571620d63772ad0b177d4e7 Mon Sep 17 00:00:00 2001 From: Reece Date: Mon, 24 Apr 2023 19:39:36 +0100 Subject: [PATCH] [*] TryLockRead was unware of RWRenterableLocks specifications (not an issue for regular blocking lock paths) --- Source/Threading/Primitives/AuRWLock.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Source/Threading/Primitives/AuRWLock.cpp b/Source/Threading/Primitives/AuRWLock.cpp index 13886145..f25d457c 100644 --- a/Source/Threading/Primitives/AuRWLock.cpp +++ b/Source/Threading/Primitives/AuRWLock.cpp @@ -7,6 +7,7 @@ ***/ #include #include "AuRWLock.hpp" +#include "SMTYield.hpp" namespace Aurora::Threading::Primitives { @@ -210,14 +211,17 @@ namespace Aurora::Threading::Primitives template bool RWLockImpl::TryLockRead() { - auto iCurState = this->state_; - - if (iCurState == -1) + return DoTryIf([=]() { - return this->reentrantWriteLockHandle_ == GetThreadCookie(); - } + auto iCurState = this->state_; - return AuAtomicCompareExchange(&this->state_, iCurState + 1, iCurState) == iCurState; + if (iCurState < 0) + { + return this->reentrantWriteLockHandle_ == GetThreadCookie(); + } + + return AuAtomicCompareExchange(&this->state_, iCurState + 1, iCurState) == iCurState; + }); } template