[*] ITimer comment and win32 patch

This commit is contained in:
Reece Wilson 2023-12-09 12:09:45 +00:00
parent 783bed0d85
commit fe529b31da
3 changed files with 22 additions and 14 deletions

View File

@ -52,6 +52,9 @@ namespace Aurora::IO::Loop
struct ITimer : virtual ILoopSource
{
/* Warning: IO timers use wall time (CurrentClock[M/NS), not SteadyClock[M/N]S()).
Use auasync timers for steady-clock timing and tick timing information. */
virtual void UpdateTime(AuUInt64 absTimeMs) = 0;
virtual void UpdateTimeNs(AuUInt64 absTimeNs) = 0;
virtual void UpdateTickRateIfAny(AuUInt32 reschedStepMsOrZero = 0, AuUInt32 maxIterationsOrZero = 0) = 0;

View File

@ -29,17 +29,15 @@ namespace Aurora::IO::Loop
void LSTimer::UpdateTime(AuUInt64 absTimeMs)
{
this->targetTime_ = AuTime::ConvertTimestamp(absTimeMs);
UpdateTimeInternal(this->targetTime_);
UpdateTimeInternalNTWall(AuTime::ConvertTimestamp(absTimeMs));
}
void LSTimer::UpdateTimeNs(AuUInt64 absTimeNs)
{
this->targetTime_ = AuTime::ConvertTimestampNs(absTimeNs);
UpdateTimeInternal(this->targetTime_);
UpdateTimeInternalNTWall(AuTime::ConvertTimestampNs(absTimeNs));
}
void LSTimer::UpdateTimeInternal(AuUInt64 absTimeNs)
void LSTimer::UpdateTimeInternalNTWall(AuUInt64 absTimeNs)
{
LARGE_INTEGER i;
this->targetTime_ = absTimeNs;
@ -52,7 +50,7 @@ namespace Aurora::IO::Loop
this->reschedStepNsOrZero_ = AuMSToNS<AuUInt64>(reschedStepMsOrZero);
this->maxIterationsOrZero_ = maxIterationsOrZero;
this->count_ = 0;
UpdateTimeInternal(this->targetTime_);
UpdateTimeInternalNTWall(this->targetTime_);
}
void LSTimer::UpdateTickRateIfAnyNs(AuUInt64 reschedStepNsOrZero, AuUInt32 maxIterationsOrZero)
@ -60,28 +58,35 @@ namespace Aurora::IO::Loop
this->reschedStepNsOrZero_ = reschedStepNsOrZero;
this->maxIterationsOrZero_ = maxIterationsOrZero;
this->count_ = 0;
UpdateTimeInternal(this->targetTime_);
UpdateTimeInternalNTWall(this->targetTime_);
}
bool LSTimer::OnTrigger(AuUInt handle)
{
SysAssert(this->targetTime_ <= AuTime::ConvertTimestampNs(AuTime::CurrentClockNS()));
if (!this->reschedStepNsOrZero_)
{
return true;
}
auto uCurrentTime = AuTime::ConvertTimestampNs(AuTime::CurrentClockNS());
auto uNextTick = this->targetTime_ + (AuUInt64(this->reschedStepNsOrZero_) / 100ULL);
if (this->targetTime_ > uCurrentTime ||
uCurrentTime > uNextTick)
{
this->targetTime_ = uCurrentTime;
uNextTick = this->targetTime_ + (AuUInt64(this->reschedStepNsOrZero_) / 100ULL);
}
if (!this->maxIterationsOrZero_)
{
this->UpdateTimeInternal(this->targetTime_ + (AuUInt64(this->reschedStepNsOrZero_) / 100ULL));
this->UpdateTimeInternalNTWall(uNextTick);
return true;
}
bool ok = AuAtomicAdd<AuUInt32>(&this->count_, 1) <= this->maxIterationsOrZero_;
if (ok)
if (AuAtomicAdd<AuUInt32>(&this->count_, 1) <= this->maxIterationsOrZero_)
{
this->UpdateTimeInternal(this->targetTime_ + (AuUInt64(this->reschedStepNsOrZero_) / 100ULL));
this->UpdateTimeInternalNTWall(uNextTick);
return true;
}
else

View File

@ -27,7 +27,7 @@ namespace Aurora::IO::Loop
virtual bool WaitOn(AuUInt32 timeout) override;
virtual ELoopSource GetType() override;
void UpdateTimeInternal(AuUInt64 absTimeNs);
void UpdateTimeInternalNTWall(AuUInt64 absTimeNs);
private:
AuUInt64 reschedStepNsOrZero_ {0};