[*] Release AuAsyncTimer callback references as soon as the object is canceled

This commit is contained in:
Reece Wilson 2024-05-28 17:28:14 +01:00
parent d520b0ce42
commit 85cf0a793a
2 changed files with 22 additions and 5 deletions

View File

@ -28,7 +28,9 @@ namespace Aurora::Async
void AsyncFuncTimer::CancelTimer()
{
AU_LOCK_GUARD(this->mutex);
this->Cancel();
AuResetMember(this->pCallback);
}
AuUInt64 AsyncFuncTimer::GetLastTime()
@ -53,6 +55,7 @@ namespace Aurora::Async
void AsyncFuncTimer::DispatchTask(IWorkItemHandler::ProcessInfo &info)
{
AU_LOCK_GUARD(this->mutex);
info.type = ETickType::eRerun;
auto uTickCount = ++this->uTickCount;
@ -68,6 +71,13 @@ namespace Aurora::Async
info.reschedSteadyClockAbsNs = this->uNextTickTime;
if (!this->pCallback)
{
return;
}
try
{
if (this->pCallback->OnTick(uTickCount, uDelta, this->uLastTickTime))
{
info.type = ETickType::eSchedule;
@ -77,6 +87,12 @@ namespace Aurora::Async
info.type = ETickType::eFinished;
}
}
catch (...)
{
info.type = ETickType::eSchedule;
SysPushErrorCatch();
}
}
void AsyncFuncTimer::Cleanup()
{

View File

@ -37,5 +37,6 @@ namespace Aurora::Async
AuUInt64 uInterval {};
AuUInt64 uTickCount {};
bool bCatchUp { false };
AuCriticalSection mutex;
};
}