[+] AuIO::Loop::WaitMultipleLoopSourcesEx

This commit is contained in:
Reece Wilson 2023-12-10 22:22:14 +00:00
parent 0747ff230e
commit 5541c25050
2 changed files with 25 additions and 3 deletions

View File

@ -27,6 +27,15 @@ namespace Aurora::IO::Loop
bool bAny = true,
AuOptional<AuUInt32> optTimeoutMS = {});
static const AuUInt64 kWaitMultipleFlagAny = 1 << 0;
static const AuUInt64 kWaitMultipleFlagNoSpin = 1 << 1;
static const AuUInt64 kWaitMultipleFlagAvoidKern = 1 << 2;
AUKN_SYM bool WaitMultipleLoopSourcesEx(const AuList<AuSPtr<Loop::ILoopSource>> &lsList,
AuList<AuSPtr<Loop::ILoopSource>> &signaled,
AuUInt64 uFlags = { kWaitMultipleFlagAny },
AuOptional<AuUInt32> optTimeoutMS = {});
struct ILSSemaphore : virtual ILoopSource
{
virtual bool AddOne() = 0;

View File

@ -92,6 +92,14 @@ namespace Aurora::IO::Loop
AuList<AuSPtr<Loop::ILoopSource>> &signaled,
bool bAny,
AuOptionalEx<AuUInt32> optTimeoutMS)
{
return WaitMultipleLoopSourcesEx(lsList, signaled, bAny ? kWaitMultipleFlagAny : 0, optTimeoutMS);
}
AUKN_SYM bool WaitMultipleLoopSourcesEx(const AuList<AuSPtr<Loop::ILoopSource>> &lsList,
AuList<AuSPtr<Loop::ILoopSource>> &signaled,
AuUInt64 uFlags,
AuOptional<AuUInt32> optTimeoutMS)
{
signaled.clear();
AuList<AuUInt32> reverseList;
@ -100,7 +108,10 @@ namespace Aurora::IO::Loop
{
return true;
}
bool bAny { bool(uFlags & kWaitMultipleFlagAny) };
bool bSpin { !(uFlags & kWaitMultipleFlagNoSpin) };
bool bAvoidKrn { bool(uFlags & kWaitMultipleFlagAvoidKern) };
bool bZeroTick { optTimeoutMS && optTimeoutMS.value() == 0 };
bool bHasTimeOut { optTimeoutMS && optTimeoutMS.value() };
bool bSleepForever { !optTimeoutMS };
@ -181,7 +192,8 @@ namespace Aurora::IO::Loop
}
}
if (lsList.size() > 1)
if (lsList.size() > 1 &&
(!bAvoidKrn || signaled.empty()))
{
for (AU_ITERATE_N_TO_X(i, 1, lsList.size()))
{
@ -303,7 +315,8 @@ namespace Aurora::IO::Loop
}
};
if (gRuntimeConfig.threadingConfig.bPlatformIsSMPProcessorOptimized &&
if (bSpin &&
gRuntimeConfig.threadingConfig.bPlatformIsSMPProcessorOptimized &&
!bZeroTick)
{
AuThreadPrimitives::DoTryIf([&]()