[+] ThreadingConfig::uUWPNanosecondEmulationMaxYields

[+] ThreadingConfig::bUWPNanosecondEmulationCheckFirst
This commit is contained in:
Reece Wilson 2023-08-22 09:55:05 +01:00
parent cf363b9f5b
commit 3747fb7c6f
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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<AuUInt32>(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();
}