From 9fea60a9ed8eabee888a2ba351a64d2e92538e46 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sat, 2 Dec 2023 11:06:49 +0000 Subject: [PATCH] [*] 64ce35dd cont --- Include/Aurora/IO/Loop/Loop.hpp | 7 +++++-- Source/IO/Loop/Loop.cpp | 27 +++++++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Include/Aurora/IO/Loop/Loop.hpp b/Include/Aurora/IO/Loop/Loop.hpp index 11a354c9..3b3e9066 100644 --- a/Include/Aurora/IO/Loop/Loop.hpp +++ b/Include/Aurora/IO/Loop/Loop.hpp @@ -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> &lsList, AuList> &signaled, bool bAny = true, - AuOptionalEx uTimeoutMS = 0); + AuOptional optTimeoutMS = {}); struct ILSSemaphore : virtual ILoopSource { diff --git a/Source/IO/Loop/Loop.cpp b/Source/IO/Loop/Loop.cpp index da01de83..a14825f6 100644 --- a/Source/IO/Loop/Loop.cpp +++ b/Source/IO/Loop/Loop.cpp @@ -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(optTimeoutMS) : + AuUInt64 uTimeoutEnd = bHasTimeOut ? + AuTime::SteadyClockNS() + AuMSToNS(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) {