From e1f384de2e55f9835e6721d039c577b573150b62 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Mon, 21 Aug 2023 16:19:14 +0100 Subject: [PATCH] [*] RWLock: improper upgrade handshake The switch over to two condvars still doesnt seem right --- Source/Threading/Primitives/AuRWLock.cpp | 32 ++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Source/Threading/Primitives/AuRWLock.cpp b/Source/Threading/Primitives/AuRWLock.cpp index 9f15d535..8ab17a99 100644 --- a/Source/Threading/Primitives/AuRWLock.cpp +++ b/Source/Threading/Primitives/AuRWLock.cpp @@ -288,12 +288,22 @@ namespace Aurora::Threading::Primitives return false; } } - + #if defined(AURWLOCK_NO_SIZE_OPTIMIZED_CONDVAR) - if (!this->GetConditionWriter().WaitForSignalNS(iSecondTimeout)) + bool bStatus = this->GetConditionWriter().WaitForSignalNS(iSecondTimeout); #else - if (!this->GetConditionWriter().WaitForSignalNsEx(AuUnsafeRaiiToShared(&this->mutex_), iSecondTimeout)) + bool bStatus = this->GetConditionWriter().WaitForSignalNsEx(AuUnsafeRaiiToShared(&this->mutex_), iSecondTimeout); #endif + + if constexpr (bIsWriteRecursionAllowed) + { + if (this->state_ == 1) + { + this->GetConditionWriter().Broadcast(); + } + } + + if (!bStatus) { AuAtomicSub(&this->writersPending_, 1); return false; @@ -308,6 +318,7 @@ namespace Aurora::Threading::Primitives } else { + // TBD: this->GetConditionWriter().Broadcast(); this->GetCondition().Broadcast(); } @@ -370,10 +381,20 @@ namespace Aurora::Threading::Primitives } #if defined(AURWLOCK_NO_SIZE_OPTIMIZED_CONDVAR) - if (!this->GetConditionWriter().WaitForSignalNS(uSecondTimeout)) + bool bStatus = this->GetConditionWriter().WaitForSignalNS(uSecondTimeout); #else - if (!this->GetConditionWriter().WaitForSignalNsEx(AuUnsafeRaiiToShared(&this->mutex_), uSecondTimeout)) + bool bStatus = this->GetConditionWriter().WaitForSignalNsEx(AuUnsafeRaiiToShared(&this->mutex_), uSecondTimeout); #endif + + if constexpr (bIsWriteRecursionAllowed) + { + if (this->state_ == 1) + { + this->GetConditionWriter().Broadcast(); + } + } + + if (!bStatus) { AuAtomicSub(&this->writersPending_, 1); return false; @@ -388,6 +409,7 @@ namespace Aurora::Threading::Primitives } else { + // TBD: this->GetConditionWriter().Broadcast(); this->GetCondition().Broadcast(); }