[*] Fix busted nt timeouts under loopsource waits

This commit is contained in:
Reece Wilson 2023-12-23 08:03:59 +00:00
parent cdfb35d5a8
commit 1576f56d19

View File

@ -21,10 +21,33 @@ namespace Aurora::IO::Loop
{
one = 0;
DWORD ret;
DWORD ret { WAIT_IO_COMPLETION };
AuUInt64 uEndTimeSteady = timeout ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) :
0;
do
{
ret = WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handles.at(0)), timeout, true);
AuUInt32 uRemMS { INFINITE };
ret = WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handles.at(0)), uRemMS, true);
if (timeout &&
ret != WAIT_IO_COMPLETION &&
ret != WAIT_OBJECT_0)
{
auto uNow = AuTime::SteadyClockNS();
if (uNow >= uEndTimeSteady)
{
break;
}
uRemMS = AuNSToMS<AuUInt64>(uEndTimeSteady);
if (!uRemMS)
{
break;
}
}
}
while (ret == WAIT_IO_COMPLETION);
@ -43,15 +66,45 @@ namespace Aurora::IO::Loop
}
}
auto idx = WaitForMultipleObjectsEx(ntHandles.size(), ntHandles.data(), false, timeout, true);
if (idx < WAIT_OBJECT_0)
DWORD ret { WAIT_IO_COMPLETION };
AuUInt64 uEndTimeSteady = timeout ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) : 0;
do
{
return false;
AuUInt32 uRemMS { INFINITE };
ret = WaitForMultipleObjectsEx(ntHandles.size(), ntHandles.data(), false, uRemMS, true);
if (ret < WAIT_OBJECT_0)
{
continue;
}
one = handles[idx];
if (ret < ntHandles.size())
{
one = handles[ret];
return true;
}
if (timeout)
{
auto uNow = AuTime::SteadyClockNS();
if (uNow >= uEndTimeSteady)
{
break;
}
uRemMS = AuNSToMS<AuUInt64>(uEndTimeSteady);
if (!uRemMS)
{
break;
}
}
}
while (ret == WAIT_IO_COMPLETION);
return false;
}
}
bool WaitSingleGeneric::WaitForOne(AuUInt32 timeout, AuUInt handle)