[*] Suppress spurious IO wakeups in WaitSingleBase
This commit is contained in:
parent
60bb1020ce
commit
18c023acae
@ -59,40 +59,60 @@ namespace Aurora::IO::Loop
|
||||
bool val {};
|
||||
AuUInt one {AuNumericLimits<AuUInt>::max()};
|
||||
AuUInt two {AuNumericLimits<AuUInt>::max()};
|
||||
|
||||
this->OnPresleep();
|
||||
|
||||
if (this->Singular())
|
||||
{
|
||||
#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
|
||||
auto uEndTime = timeout ?
|
||||
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) :
|
||||
0;
|
||||
|
||||
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();
|
||||
return val;
|
||||
|
Loading…
Reference in New Issue
Block a user