[*] (Disabled) bad optimization: possibility to disable spinning of the auasync task scheduler. Worsens CPU usage when spinning is desired on the target platform, when paired with the two platforms this optimization would've benefited, Windows 7 and Linux.

This commit is contained in:
Reece Wilson 2024-05-05 20:17:19 +01:00
parent f3ba901f71
commit 316fb3f6b2

View File

@ -13,6 +13,10 @@
#include <Console/Commands/Commands.hpp>
#include "IAsyncRunnable.hpp"
//#include <Source/Threading/Primitives/AuConditionMutex.Generic.hpp>
//#include <Source/Threading/Primitives/AuConditionVariable.Generic.hpp>
//#define SCHEDULER_USE_NO_SPIN
namespace Aurora::Async
{
struct SchedEntry
@ -26,7 +30,11 @@ namespace Aurora::Async
// sched thread threading:
static AuThreads::ThreadUnique_t gThread;
static AuConditionMutex gSchedLock;
#if !defined(SCHEDULER_USE_NO_SPIN)
static AuConditionVariable gSchedCondvar(AuUnsafeRaiiToShared(gSchedLock.AsPointer()));
#else
static AuThreadPrimitives::ConditionVariableInternal gSchedCondvar;
#endif
// next tick timing:
static AuUInt64 uNextSysTickGuessed {};
@ -109,7 +117,11 @@ namespace Aurora::Async
}
}
#if !defined(SCHEDULER_USE_NO_SPIN)
gSchedCondvar->Signal();
#else
gSchedCondvar.Signal();
#endif
}
static void SchedThread()
@ -132,7 +144,12 @@ namespace Aurora::Async
if (uNow < uNextTick)
{
uNextSysTickGuessed = 0;
#if !defined(SCHEDULER_USE_NO_SPIN)
gSchedCondvar->WaitForSignalNS(uNextTick - uNow);
#else
gSchedCondvar.WaitForSignalNsEx(&AuStaticCast<AuThreadPrimitives::ConditionMutexImpl>(gSchedLock.AsPointer())->mutex, uNextTick - uNow, false);
#endif
}
else if (uNow >= uNextTick)
{
@ -140,9 +157,16 @@ namespace Aurora::Async
}
else if (uNextSysTickGuessed == 0)
{
#if !defined(SCHEDULER_USE_NO_SPIN)
gSchedCondvar->WaitForSignalNS(gRuntimeConfig.async.bEnableLegacyTicks ?
AuMSToNS<AuUInt64>(gRuntimeConfig.async.dwLegacyMainThreadSystemTickMS) :
0);
#else
gSchedCondvar.WaitForSignalNsEx(&AuStaticCast<AuThreadPrimitives::ConditionMutexImpl>(gSchedLock.AsPointer())->mutex, gRuntimeConfig.async.bEnableLegacyTicks ?
AuMSToNS<AuUInt64>(gRuntimeConfig.async.dwLegacyMainThreadSystemTickMS) :
0,
false);
#endif
}
if (gRuntimeConfig.async.dwSchedulerRateLimitNS)
@ -192,7 +216,11 @@ namespace Aurora::Async
{
gThread->SendExitSignal();
}
#if !defined(SCHEDULER_USE_NO_SPIN)
gSchedCondvar->Broadcast();
#else
gSchedCondvar.Broadcast();
#endif
gThread.reset();
}