diff --git a/Include/Aurora/Runtime.hpp b/Include/Aurora/Runtime.hpp index ddd85dce..75e52d1c 100644 --- a/Include/Aurora/Runtime.hpp +++ b/Include/Aurora/Runtime.hpp @@ -344,12 +344,11 @@ namespace Aurora { // WARN: these values are not final - bool bNoThreadNames { false }; - bool bPlatformIsSMPProcessorOptimized { true }; // Whether to attempt to using mm_pause or similar before yielding into the kernel - AuUInt8 uSpinLoopPowerA { 80 }; // Nudgable spinloop power. This is our local userland niceness factor - // This is comparable to Win32's SetCriticalSectionSpinCount applied across every single AuThreadPrimitives try-lock and lock. - // Adjust this value to compensate for longer critical sections when context switching isn't preferrable. - AuUInt8 uSpinLoopLinearBit { 1 }; + bool bNoThreadNames { false }; + bool bPlatformIsSMPProcessorOptimized { true }; // Whether to attempt to using mm_pause or similar instruction before yielding into the kernel + AuUInt16 uSpinLoopPowerA { 128 }; // Nudgable spinloop power. This is our local userland niceness factor + // This is comparable to Win32's SetCriticalSectionSpinCount applied across every single AuThreadPrimitives try-lock and lock. + // Adjust this value to compensate for longer critical sections when context switching isn't preferrable. AuUInt64 bEnableAggressiveScheduling : 1 { false }; AuUInt64 bEnableAgrSchedulingRatelimit : 1 { true }; AuUInt64 bPreferNt51XpMutexesOver8 : 1 { false }; @@ -366,10 +365,10 @@ namespace Aurora AuUInt64 bPreferWaitOnAddressAlwaysSpin : 1 { true }; // ..., if emulated! if double-spinning under higher level locks, disable me. AuUInt64 bPreferRWLockReadLockSpin : 1 { true }; AuUInt64 bUWPNanosecondEmulationCheckFirst : 1 { false }; - AuUInt64 bForceEnableAdaptiveSpin : 1 { false }; - AuUInt64 bPreferEnableAdaptiveSpin : 1 { true }; - AuUInt64 uUWPNanosecondEmulationMaxYields : 7 { 12 }; - AuUInt64 bPreferLinuxAdaptiveSpin : 1 { true }; + AuUInt64 uUWPNanosecondEmulationMaxYields : 7 { 12 }; + AuUInt64 bForceEnableAdaptiveSpin : 1 { false }; // || + AuUInt64 bPreferEnableAdaptiveSpin : 1 { true }; // && + AuUInt64 bPreferLinuxAdaptiveSpin : 1 { true }; // && AuUInt64 bPreferOldWin32AdaptiveSpin : 1 { false }; AuUInt64 bPreferNewWin32AdaptiveSpin : 1 { true }; AuUInt64 uAdaptiveSpinCUCnt0 : 4 { 0 }; diff --git a/Source/Async/ThreadPool.cpp b/Source/Async/ThreadPool.cpp index dbe6ab9c..0f4db8b0 100644 --- a/Source/Async/ThreadPool.cpp +++ b/Source/Async/ThreadPool.cpp @@ -485,7 +485,6 @@ namespace Aurora::Async { if (InRunnerMode()) { - if ((this->uAtomicCounter == 0) && this->IsDepleted()) { diff --git a/Source/Threading/Primitives/SMTYield.hpp b/Source/Threading/Primitives/SMTYield.hpp index 02c9e410..e748d899 100644 --- a/Source/Threading/Primitives/SMTYield.hpp +++ b/Source/Threading/Primitives/SMTYield.hpp @@ -56,31 +56,36 @@ namespace Aurora::Threading::Primitives int loops = spin; while (loops > 0) { - loops -= 1; - if (callback()) { AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u); return true; } + else + { + SMPPause(); + SMPPause(); + SMPPause(); + SMPPause(); + loops -= 4; + } } if (gHasThreadLocalTimeout) { - auto uCount = tlsSpinCountLocal; - - int loops = (1 << uCount); + int loops = (1 << tlsSpinCountLocal); while (loops > 0) { - SMPPause(); - - loops -= 1; - if (callback()) { AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u); return true; } + else + { + SMPPause(); + loops--; + } } } @@ -91,15 +96,16 @@ namespace Aurora::Threading::Primitives int loops = (spin) / 3; while (loops > 0) { - SMPPause(); - - loops -= 1; - if (callback()) { AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u); return true; } + else + { + SMPPause(); + loops --; + } } } @@ -110,12 +116,18 @@ namespace Aurora::Threading::Primitives int loops = spin; while (loops > 0) { - loops -= 1; - if (callback()) { return true; } + else + { + SMPPause(); + SMPPause(); + SMPPause(); + SMPPause(); + loops -= 4; + } } if (gHasThreadLocalTimeout) @@ -125,14 +137,15 @@ namespace Aurora::Threading::Primitives int loops = (1 << uCount); while (loops > 0) { - SMPPause(); - - loops -= 1; - if (callback()) { return true; } + else + { + SMPPause(); + loops --; + } } } }