[*] Cont work on WaitMultipleLoopSources's yield time

This commit is contained in:
Reece Wilson 2023-12-02 03:39:41 +00:00
parent b9e8b138f7
commit 64ce35dd87

View File

@ -91,7 +91,7 @@ namespace Aurora::IO::Loop
AUKN_SYM bool WaitMultipleLoopSources(const AuList<AuSPtr<Loop::ILoopSource>> &lsList,
AuList<AuSPtr<Loop::ILoopSource>> &signaled,
bool bAny,
AuOptionalEx<AuUInt32> uTimeoutMS)
AuOptionalEx<AuUInt32> optTimeoutMS)
{
signaled.clear();
AuList<AuUInt32> reverseList;
@ -110,9 +110,9 @@ namespace Aurora::IO::Loop
}
bool bStatus {};
if (uTimeoutMS)
if (optTimeoutMS)
{
bStatus = pSource->WaitOn(uTimeoutMS.value());
bStatus = pSource->WaitOn(optTimeoutMS.value());
}
else
{
@ -127,10 +127,11 @@ namespace Aurora::IO::Loop
return bStatus;
}
auto uTimeoutEnd = uTimeoutMS ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(uTimeoutMS) :
AuUInt64 uTimeoutEnd = optTimeoutMS.has_value() && optTimeoutMS.value() ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(optTimeoutMS) :
0;
bool bZeroTick { optTimeoutMS && optTimeoutMS.value() == 0 };
AU_DEBUG_MEMCRUNCH;
signaled.reserve(lsList.size());
@ -146,7 +147,22 @@ namespace Aurora::IO::Loop
if (entryZero)
{
if (!entryZero->WaitOn(uTimeoutMS))
bool bStatus {};
if (!optTimeoutMS || optTimeoutMS.value() == 0)
{
bStatus = entryZero->WaitOn(0);
}
else if (bZeroTick)
{
bStatus = entryZero->IsSignaled();
}
else if (optTimeoutMS)
{
bStatus = entryZero->WaitOn(optTimeoutMS.value());
}
if (!bStatus)
{
goto next;
}
@ -168,19 +184,37 @@ namespace Aurora::IO::Loop
auto uStartTime = Time::SteadyClockNS();
if (uStartTime >= uTimeoutEnd)
{
#if 0
break;
#else
bZeroTick = true;
#endif
}
uTimeoutMS = AuNSToMS<AuInt64>(uTimeoutEnd - uStartTime);
if (!uTimeoutMS)
{
#if 0
break;
#else
bZeroTick = true;
#endif
}
}
if (!lsList[i]->WaitOn(uTimeoutMS))
if (bZeroTick)
{
break;
if (!lsList[i]->IsSignaled())
{
break;
}
}
else
{
if (!lsList[i]->WaitOn(uTimeoutMS))
{
break;
}
}
reverseList.push_back(i);
@ -247,7 +281,8 @@ namespace Aurora::IO::Loop
}
};
if (gRuntimeConfig.threadingConfig.bPlatformIsSMPProcessorOptimized)
if (gRuntimeConfig.threadingConfig.bPlatformIsSMPProcessorOptimized &&
!bZeroTick)
{
AuThreadPrimitives::DoTryIf([&]()
{
@ -255,24 +290,40 @@ namespace Aurora::IO::Loop
return lsList2.size() != lsList.size() ||
!bAnyFound;
});
}
if (bAnyFound || !gRuntimeConfig.threadingConfig.bPlatformIsSMPProcessorOptimized)
if (bAnyFound)
{
DoTheThing();
}
}
else
{
DoTheThing();
}
if (lsList2.size())
{
bool bZeroTick { };
if ((bZeroTick = bool(signalTemp.size())))
bZeroTick |= bool(signalTemp.size());
AuUInt32 uTimeoutMS {};
if (uTimeoutEnd)
{
uTimeoutMS = 1;
auto uStartTime = Time::SteadyClockNS();
if (uStartTime >= uTimeoutEnd)
{
bZeroTick = true;
}
uTimeoutMS = AuNSToMS<AuInt64>(uTimeoutEnd - uStartTime);
if (!uTimeoutMS)
{
bZeroTick = true;
}
}
#if defined(AURORA_IS_MODERNNT_DERIVED)
signaled = WaitMultipleOrObjects(lsList2, bZeroTick, uTimeoutMS);
bTimedout = uTimeoutMS && !bZeroTick ?
bTimedout = uTimeoutEnd && uTimeoutMS && !bZeroTick ?
Time::SteadyClockNS() >= uTimeoutEnd :
false;
#else