This commit is contained in:
Reece Wilson 2023-12-02 11:06:49 +00:00
parent 880388ea73
commit 9fea60a9ed
2 changed files with 22 additions and 12 deletions

View File

@ -18,11 +18,14 @@
#include "ILoopQueue.hpp"
namespace Aurora::IO::Loop
{
{
// optTimeoutMS = {} | indefinite
// optTimeoutMS = 0 | poll
// optTimeoutMS = 1 | 1ms
AUKN_SYM bool WaitMultipleLoopSources(const AuList<AuSPtr<Loop::ILoopSource>> &lsList,
AuList<AuSPtr<Loop::ILoopSource>> &signaled,
bool bAny = true,
AuOptionalEx<AuUInt32> uTimeoutMS = 0);
AuOptional<AuUInt32> optTimeoutMS = {});
struct ILSSemaphore : virtual ILoopSource
{

View File

@ -101,6 +101,10 @@ namespace Aurora::IO::Loop
return true;
}
bool bZeroTick { optTimeoutMS && optTimeoutMS.value() == 0 };
bool bHasTimeOut { optTimeoutMS && optTimeoutMS.value() };
bool bSleepForever { !optTimeoutMS };
if (lsList.size() == 1)
{
auto pSource = lsList[0];
@ -110,7 +114,11 @@ namespace Aurora::IO::Loop
}
bool bStatus {};
if (optTimeoutMS)
if (bSleepForever)
{
bStatus = pSource->WaitOn(0);
}
else if (bHasTimeOut)
{
bStatus = pSource->WaitOn(optTimeoutMS.value());
}
@ -127,10 +135,9 @@ namespace Aurora::IO::Loop
return bStatus;
}
AuUInt64 uTimeoutEnd = optTimeoutMS.has_value() && optTimeoutMS.value() ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(optTimeoutMS) :
AuUInt64 uTimeoutEnd = bHasTimeOut ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(optTimeoutMS.value()) :
0;
bool bZeroTick { optTimeoutMS && optTimeoutMS.value() == 0 };
AU_DEBUG_MEMCRUNCH;
@ -149,18 +156,18 @@ namespace Aurora::IO::Loop
{
bool bStatus {};
if (!optTimeoutMS || optTimeoutMS.value() == 0)
if (bSleepForever)
{
bStatus = entryZero->WaitOn(0);
}
else if (bZeroTick)
{
bStatus = entryZero->IsSignaled();
}
else if (optTimeoutMS)
else if (bHasTimeOut)
{
bStatus = entryZero->WaitOn(optTimeoutMS.value());
}
else
{
bStatus = entryZero->IsSignaled();
}
if (!bStatus)
{