From cf118d0b4b6012239117b796ec67d02b7885eee7 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Wed, 30 Aug 2023 14:57:13 +0100 Subject: [PATCH] [*] Minor RW lock tweaks --- Source/Threading/Primitives/AuRWLock.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Source/Threading/Primitives/AuRWLock.cpp b/Source/Threading/Primitives/AuRWLock.cpp index 8be9e20c..d2b8eb56 100644 --- a/Source/Threading/Primitives/AuRWLock.cpp +++ b/Source/Threading/Primitives/AuRWLock.cpp @@ -474,7 +474,8 @@ namespace Aurora::Threading::Primitives if constexpr (bIsWriteRecursionAllowed) { - if (this->state_ == 1) + if (AuAtomicLoad(&this->state_) == 1 && + AuAtomicLoad(&this->writersPending_)) { this->SignalManyWriter(); } @@ -652,7 +653,7 @@ namespace Aurora::Threading::Primitives if (!gUseFutexRWLock) { AU_LOCK_GUARD(this->mutex_); /* actually locking this->state_, out of branch. required for the mutually exclusive correctness of the condition. this is a fence. */ - bElevation = this->writersPending_ > 0; + bElevation = AuAtomicLoad(&this->writersPending_) > 0; } else { @@ -663,10 +664,6 @@ namespace Aurora::Threading::Primitives { this->SignalOneWriter(); } - else - { - this->SignalManyReader(); - } } } @@ -683,7 +680,7 @@ namespace Aurora::Threading::Primitives { AU_LOCK_GUARD(this->mutex_); AuAtomicStore(&this->state_, 0); - bElevationPending = this->writersPending_ > 0; + bElevationPending = AuAtomicLoad(&this->writersPending_) > 0; } else { @@ -725,11 +722,11 @@ namespace Aurora::Threading::Primitives if (!gUseFutexRWLock) { AU_LOCK_GUARD(this->mutex_); - bElevationPending = this->writersPending_ > 0; + bElevationPending = AuAtomicLoad(&this->writersPending_) > 0; } else { - bElevationPending = this->writersPending_ > 0; + bElevationPending = AuAtomicLoad(&this->writersPending_) > 0; } if (bElevationPending)