[*] Suppress spurious IO wakeups in WaitSingleBase

This commit is contained in:
Reece Wilson 2023-10-21 06:18:49 +01:00
parent 60bb1020ce
commit 18c023acae

View File

@ -59,40 +59,60 @@ namespace Aurora::IO::Loop
bool val {}; bool val {};
AuUInt one {AuNumericLimits<AuUInt>::max()}; AuUInt one {AuNumericLimits<AuUInt>::max()};
AuUInt two {AuNumericLimits<AuUInt>::max()}; AuUInt two {AuNumericLimits<AuUInt>::max()};
this->OnPresleep(); this->OnPresleep();
if (this->Singular()) auto uEndTime = timeout ?
{ AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) :
#if defined(AURORA_IS_POSIX_DERIVED) 0;
auto handle = this->GetHandle();
auto handleRw = this->GetWriteHandle();
val = this->WaitForOne(timeout ? timeout : AuUInt32(-1), handle, handleRw);
#else
auto handle = this->GetHandle();
val = this->WaitForOne(timeout ? timeout : AuUInt32(-1), handle);
#endif
if (val)
{
val = this->OnTrigger(handle);
}
}
else
{
#if defined(AURORA_IS_POSIX_DERIVED)
auto handles = this->GetHandles();
auto handlesRw = this->GetWriteHandles();
val = this->WaitForAtleastOne(timeout ? timeout : AuUInt32(-1), handles, handlesRw, one, two);
if (one == -1) one = two;
#else
auto handles = this->GetHandles();
val = this->WaitForAtleastOne(timeout ? timeout : AuUInt32(-1), handles, one);
#endif
if (val) do
{
if (this->Singular())
{ {
val = this->OnTrigger(one); #if defined(AURORA_IS_POSIX_DERIVED)
auto handle = this->GetHandle();
auto handleRw = this->GetWriteHandle();
val = this->WaitForOne(timeout ? timeout : AuUInt32(-1), handle, handleRw);
#else
auto handle = this->GetHandle();
val = this->WaitForOne(timeout ? timeout : AuUInt32(-1), handle);
#endif
if (val)
{
val = this->OnTrigger(handle);
}
}
else
{
#if defined(AURORA_IS_POSIX_DERIVED)
auto handles = this->GetHandles();
auto handlesRw = this->GetWriteHandles();
val = this->WaitForAtleastOne(timeout ? timeout : AuUInt32(-1), handles, handlesRw, one, two);
if (one == -1) one = two;
#else
auto handles = this->GetHandles();
val = this->WaitForAtleastOne(timeout ? timeout : AuUInt32(-1), handles, one);
#endif
if (val)
{
val = this->OnTrigger(one);
}
}
if (timeout)
{
auto uStartTime = Time::SteadyClockNS();
if (uStartTime >= uEndTime)
{
return false;
}
timeout = AuNSToMS<AuInt64>(uEndTime - uStartTime);
} }
} }
while (timeout && !val);
this->OnFinishSleep(); this->OnFinishSleep();
return val; return val;