From 3747fb7c6ff1e1a2ad5a37a2b0ead2984c958268 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Tue, 22 Aug 2023 09:55:05 +0100 Subject: [PATCH] [+] ThreadingConfig::uUWPNanosecondEmulationMaxYields [+] ThreadingConfig::bUWPNanosecondEmulationCheckFirst --- Include/Aurora/Runtime.hpp | 2 ++ Source/Threading/AuWakeOnAddress.cpp | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Include/Aurora/Runtime.hpp b/Include/Aurora/Runtime.hpp index 3179582d..eef0c24f 100644 --- a/Include/Aurora/Runtime.hpp +++ b/Include/Aurora/Runtime.hpp @@ -362,6 +362,8 @@ namespace Aurora AuUInt64 bPreferLinuxCondMutexSpinTryLock : 1 { true }; AuUInt64 bPreferEmulatedWakeOnAddress : 1 { false }; AuUInt64 bPreferRWLockReadLockSpin : 1 { true }; + AuUInt64 bUWPNanosecondEmulationCheckFirst: 1 { false}; + AuUInt64 uUWPNanosecondEmulationMaxYields : 7 { 12 }; }; struct DummyConfig diff --git a/Source/Threading/AuWakeOnAddress.cpp b/Source/Threading/AuWakeOnAddress.cpp index e7705caf..ef7bcfd0 100644 --- a/Source/Threading/AuWakeOnAddress.cpp +++ b/Source/Threading/AuWakeOnAddress.cpp @@ -582,6 +582,9 @@ namespace Aurora::Threading uRelativeNanoseconds = iDelta; } + auto uMaxSwitches = gRuntimeConfig.threadingConfig.uUWPNanosecondEmulationMaxYields; + auto bUWPNanosecondEmulationCheckFirst = gRuntimeConfig.threadingConfig.bUWPNanosecondEmulationCheckFirst; + // LockN(<1MS) on a platform without that resolution of yielding... damn auto uMS = AuNSToMS(uRelativeNanoseconds); if (!uMS) @@ -596,6 +599,7 @@ namespace Aurora::Threading } // second: yield + unsigned uLimit {}; do { if (!expect.Compare(pTargetAddress)) @@ -604,6 +608,14 @@ namespace Aurora::Threading } AuThreading::ContextYield(); + + if (bUWPNanosecondEmulationCheckFirst) + { + if (uLimit++ > uMaxSwitches) + { + break; + } + } } while (uAbsTimeSteadyClock > AuTime::SteadyClockNS()); // ...until times up } @@ -638,7 +650,7 @@ namespace Aurora::Threading if (!uMS) { // burn off any remainder cycles by switching contexts (this isnt a very long time usually) - if (uLimit++ < 4) + if (uLimit++ < uMaxSwitches) { AuThreading::ContextYield(); }