From 03623dfa48ae32c211bb2da231ef93f5a92b965f Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Wed, 14 Feb 2024 01:01:25 +0000 Subject: [PATCH] [*] c111dee8 cont. Simplification of if (SignalSpuriously()) AddWatcher() continued --- .../Primitives/AuConditionVariable.NT.cpp | 41 +------------------ .../Primitives/AuConditionVariable.NT.hpp | 1 - 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/Source/Threading/Primitives/AuConditionVariable.NT.cpp b/Source/Threading/Primitives/AuConditionVariable.NT.cpp index b82f73d6..80d5fb15 100644 --- a/Source/Threading/Primitives/AuConditionVariable.NT.cpp +++ b/Source/Threading/Primitives/AuConditionVariable.NT.cpp @@ -164,7 +164,7 @@ namespace Aurora::Threading::Primitives // (NT 5-6.1) Unblocks one race condition, where another thread checks out our signal, and we return with nothing. // Normal execution of the blocked thread can continue, so long as we trigger the keyed event as though this thread was signaled. // This is only relevant in an edge case of multi-waiters spinning, rapid signaling, and the IOU being hit once. Do this instead of ticketing. - this->SignalSpuriously(); + pNtReleaseKeyedEvent(gKeyedEventHandle, (void *)&this->wlist, FALSE, nullptr); } } } @@ -221,7 +221,7 @@ namespace Aurora::Threading::Primitives if (!gUseNativeWaitCondvar) { - this->SignalSpuriously(); + pNtReleaseKeyedEvent(gKeyedEventHandle, (void *)&this->wlist, FALSE, nullptr); } } } @@ -334,43 +334,6 @@ namespace Aurora::Threading::Primitives #endif } - void ConditionVariableNT::SignalSpuriously() - { - #if !defined(AURORA_FORCE_SRW_LOCKS) - auto original = this->wlist; - auto expected = original; - expected = expected >> kShiftCountByBits; - - if (expected) - { - // INTENTIONAL: Missing this->signalCount atomic increment to force another AddWaiter under successful keyedevent return - - while (expected) - { - // INTENTIONAL: Removed the -1 so we dont have to rewatch the condvar, potentially missing a signal in the process - if (AuAtomicCompareExchange(&this->wlist, (expected << kShiftCountByBits) /*intentional clear*/, original) == original) - { - if (!gUseNativeWaitCondvar) - { - pNtReleaseKeyedEvent(gKeyedEventHandle, (void *)&this->wlist, FALSE, nullptr); - } - - // INTENTIONAL: Removal of modernt branch. We err on the side of caution by failing awake, then its up to the last waking - // thread up process to block again. So long as wlist represents all the waiting threads, it doesn't matter, - // we will continue to be signalable withouts signal being lost or any thread blocking. - - return; - } - - original = this->wlist; - expected = original >> kShiftCountByBits; - } - } - #else - ::WakeConditionVariable(&this->winCond_); - #endif - } - void ConditionVariableNT::Signal() { #if !defined(AURORA_FORCE_SRW_LOCKS) diff --git a/Source/Threading/Primitives/AuConditionVariable.NT.hpp b/Source/Threading/Primitives/AuConditionVariable.NT.hpp index ecaa123b..ae9c38ff 100644 --- a/Source/Threading/Primitives/AuConditionVariable.NT.hpp +++ b/Source/Threading/Primitives/AuConditionVariable.NT.hpp @@ -19,7 +19,6 @@ namespace Aurora::Threading::Primitives bool WaitForSignalNsEx(Win32ConditionMutex *pMutex, AuUInt64 timeout, bool bSpin = true); void Signal(); - auline void SignalSpuriously(); void Broadcast(); void BroadcastN(AuUInt32 nBroadcast);