[+] IWorkItem::AddDelayTimeRepeating

[+] IWorkItem::AddDelayTimeNsRepeating
This commit is contained in:
Reece Wilson 2024-02-27 12:24:17 +00:00
parent 4ef055f81e
commit 097c0c1917
3 changed files with 35 additions and 3 deletions

View File

@ -37,10 +37,16 @@ namespace Aurora::Async
// ms = time relative to the time at which the work item would otherwise dispatch
virtual AuSPtr<IWorkItem> AddDelayTime(AuUInt32 ms) = 0;
// ns = time relative to the time at which the work item would otherwise dispatch
virtual AuSPtr<IWorkItem> AddDelayTimeNs(AuUInt64 ns) = 0;
// ms = time relative to the time at which the work item would otherwise dispatch
virtual AuSPtr<IWorkItem> AddDelayTimeRepeating(AuUInt32 ms) = 0;
// ns = time relative to the time at which the work item would otherwise dispatch
virtual AuSPtr<IWorkItem> AddDelayTimeNsRepeating(AuUInt64 ns) = 0;
// inverted WaitFor
virtual AuSPtr<IWorkItem> Then(const AuSPtr<IWorkItem> &next) = 0;

View File

@ -211,6 +211,20 @@ namespace Aurora::Async
return AU_SHARED_FROM_THIS;
}
AuSPtr<IWorkItem> WorkItem::AddDelayTimeRepeating(AuUInt32 ms)
{
this->delayTimeNs_ += AuMSToNS<AuUInt64>(ms);
this->bRepeatingTimer = true;
return AU_SHARED_FROM_THIS;
}
AuSPtr<IWorkItem> WorkItem::AddDelayTimeNsRepeating(AuUInt64 ns)
{
this->bRepeatingTimer = true;
this->delayTimeNs_ += ns;
return AU_SHARED_FROM_THIS;
}
AuSPtr<IWorkItem> WorkItem::Dispatch()
{
DispatchEx(false);
@ -296,13 +310,21 @@ namespace Aurora::Async
return;
}
if (auto delay = AuExchange(delayTimeNs_, {}))
if (auto delay = this->delayTimeNs_)
{
this->dispatchTimeNs_ = delay + Time::SteadyClockNS();
if (!this->bRepeatingTimer)
{
this->delayTimeNs_ = 0;
}
if (!Schedule())
{
this->Fail();
}
return;
}
@ -373,7 +395,8 @@ namespace Aurora::Async
}
bool bRerun = (this->pIOWatchLS && this->bIoRepeating) ||
this->waitOn_.size();
this->waitOn_.size() ||
this->bRepeatingTimer;
if (bRerun)
{

View File

@ -30,6 +30,8 @@ namespace Aurora::Async
AuSPtr<IWorkItem> SetSchedTimeNs(AuUInt64 ns) override;
AuSPtr<IWorkItem> AddDelayTime(AuUInt32 ms) override;
AuSPtr<IWorkItem> AddDelayTimeNs(AuUInt64 ns) override;
AuSPtr<IWorkItem> AddDelayTimeRepeating(AuUInt32 ms) override;
AuSPtr<IWorkItem> AddDelayTimeNsRepeating(AuUInt64 ns) override;
AuSPtr<IWorkItem> SetSchedTimeAbs(AuUInt32 ms) override;
AuSPtr<IWorkItem> SetSchedTimeNsAbs(AuUInt64 ns) override;
AuSPtr<IWorkItem> SetSchedSteadyTimeNsAbs(AuUInt64 ns) override;
@ -92,6 +94,7 @@ namespace Aurora::Async
bool finished2 {};
bool failed {};
bool bIoRepeating {};
bool bRepeatingTimer {};
bool dispatchPending_ {};
AuUInt32 ioTickCount {};
AuUInt64 dispatchTimeNs_ {};