[*] LSLocalEvent: finish optimized impl (?)

This commit is contained in:
Reece Wilson 2023-12-09 10:05:20 +00:00
parent ab030ae969
commit 783bed0d85
4 changed files with 36 additions and 3 deletions

View File

@ -58,6 +58,7 @@ namespace Aurora::IO::Loop
else
{
(void)LSSemaphore::OnTrigger(0);
AuAtomicAdd(&this->uLaterAlwaysOn, 1u);
return false;
}
}
@ -71,6 +72,7 @@ namespace Aurora::IO::Loop
else
{
(void)LSSemaphore::OnTrigger(0);
AuAtomicAdd(&this->uLaterAlwaysOn, 1u);
return false;
}
}
@ -137,6 +139,30 @@ namespace Aurora::IO::Loop
void LSLocalEvent::OnPresleep()
{
AuAtomicAdd(&this->uApproxSleepCount, 1u);
EventBits bits;
bits.state = AuAtomicLoad(&this->state_);
if (!bits.bTriggered)
{
return;
}
while (true)
{
auto uState = AuAtomicLoad(&this->uLaterAlwaysOn);
if (!uState)
{
return;
}
if (AuAtomicCompareExchange(&this->uLaterAlwaysOn, uState - 1, uState) == uState)
{
break;
}
}
LSSemaphore::AddOne();
}
void LSLocalEvent::OnFinishSleep()
@ -210,7 +236,9 @@ namespace Aurora::IO::Loop
bool LSLocalEvent::TryTakeWaitMS(AuUInt32 timeout)
{
auto uEndTime = AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout);
auto uEndTime = timeout ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) :
0;
if (this->TryTakeSpin())
{

View File

@ -60,5 +60,6 @@ namespace Aurora::IO::Loop
};
AuUInt32 uApproxSleepCount {};
AuUInt32 uLaterAlwaysOn {};
};
}

View File

@ -121,7 +121,9 @@ namespace Aurora::IO::Loop
bool LSLocalMutex::TryTakeWaitMS(AuUInt32 timeout)
{
auto uEndTime = AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout);
auto uEndTime = timeout ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) :
0;
if (this->TryTakeSpin())
{

View File

@ -163,7 +163,9 @@ namespace Aurora::IO::Loop
bool LSLocalSemaphore::TryTakeWaitMS(AuUInt32 timeout)
{
auto uEndTime = AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout);
auto uEndTime = timeout ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) :
0;
if (this->TryTakeSpin())
{