[*] (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:
parent
f3ba901f71
commit
316fb3f6b2
@ -13,6 +13,10 @@
|
|||||||
#include <Console/Commands/Commands.hpp>
|
#include <Console/Commands/Commands.hpp>
|
||||||
#include "IAsyncRunnable.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
|
namespace Aurora::Async
|
||||||
{
|
{
|
||||||
struct SchedEntry
|
struct SchedEntry
|
||||||
@ -26,7 +30,11 @@ namespace Aurora::Async
|
|||||||
// sched thread threading:
|
// sched thread threading:
|
||||||
static AuThreads::ThreadUnique_t gThread;
|
static AuThreads::ThreadUnique_t gThread;
|
||||||
static AuConditionMutex gSchedLock;
|
static AuConditionMutex gSchedLock;
|
||||||
|
#if !defined(SCHEDULER_USE_NO_SPIN)
|
||||||
static AuConditionVariable gSchedCondvar(AuUnsafeRaiiToShared(gSchedLock.AsPointer()));
|
static AuConditionVariable gSchedCondvar(AuUnsafeRaiiToShared(gSchedLock.AsPointer()));
|
||||||
|
#else
|
||||||
|
static AuThreadPrimitives::ConditionVariableInternal gSchedCondvar;
|
||||||
|
#endif
|
||||||
|
|
||||||
// next tick timing:
|
// next tick timing:
|
||||||
static AuUInt64 uNextSysTickGuessed {};
|
static AuUInt64 uNextSysTickGuessed {};
|
||||||
@ -109,7 +117,11 @@ namespace Aurora::Async
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(SCHEDULER_USE_NO_SPIN)
|
||||||
gSchedCondvar->Signal();
|
gSchedCondvar->Signal();
|
||||||
|
#else
|
||||||
|
gSchedCondvar.Signal();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SchedThread()
|
static void SchedThread()
|
||||||
@ -132,7 +144,12 @@ namespace Aurora::Async
|
|||||||
if (uNow < uNextTick)
|
if (uNow < uNextTick)
|
||||||
{
|
{
|
||||||
uNextSysTickGuessed = 0;
|
uNextSysTickGuessed = 0;
|
||||||
|
|
||||||
|
#if !defined(SCHEDULER_USE_NO_SPIN)
|
||||||
gSchedCondvar->WaitForSignalNS(uNextTick - uNow);
|
gSchedCondvar->WaitForSignalNS(uNextTick - uNow);
|
||||||
|
#else
|
||||||
|
gSchedCondvar.WaitForSignalNsEx(&AuStaticCast<AuThreadPrimitives::ConditionMutexImpl>(gSchedLock.AsPointer())->mutex, uNextTick - uNow, false);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (uNow >= uNextTick)
|
else if (uNow >= uNextTick)
|
||||||
{
|
{
|
||||||
@ -140,9 +157,16 @@ namespace Aurora::Async
|
|||||||
}
|
}
|
||||||
else if (uNextSysTickGuessed == 0)
|
else if (uNextSysTickGuessed == 0)
|
||||||
{
|
{
|
||||||
|
#if !defined(SCHEDULER_USE_NO_SPIN)
|
||||||
gSchedCondvar->WaitForSignalNS(gRuntimeConfig.async.bEnableLegacyTicks ?
|
gSchedCondvar->WaitForSignalNS(gRuntimeConfig.async.bEnableLegacyTicks ?
|
||||||
AuMSToNS<AuUInt64>(gRuntimeConfig.async.dwLegacyMainThreadSystemTickMS) :
|
AuMSToNS<AuUInt64>(gRuntimeConfig.async.dwLegacyMainThreadSystemTickMS) :
|
||||||
0);
|
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)
|
if (gRuntimeConfig.async.dwSchedulerRateLimitNS)
|
||||||
@ -192,7 +216,11 @@ namespace Aurora::Async
|
|||||||
{
|
{
|
||||||
gThread->SendExitSignal();
|
gThread->SendExitSignal();
|
||||||
}
|
}
|
||||||
|
#if !defined(SCHEDULER_USE_NO_SPIN)
|
||||||
gSchedCondvar->Broadcast();
|
gSchedCondvar->Broadcast();
|
||||||
|
#else
|
||||||
|
gSchedCondvar.Broadcast();
|
||||||
|
#endif
|
||||||
gThread.reset();
|
gThread.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user