[*] 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() void AsyncFuncTimer::CancelTimer()
{ {
AU_LOCK_GUARD(this->mutex);
this->Cancel(); this->Cancel();
AuResetMember(this->pCallback);
} }
AuUInt64 AsyncFuncTimer::GetLastTime() AuUInt64 AsyncFuncTimer::GetLastTime()
@ -53,6 +55,7 @@ namespace Aurora::Async
void AsyncFuncTimer::DispatchTask(IWorkItemHandler::ProcessInfo &info) void AsyncFuncTimer::DispatchTask(IWorkItemHandler::ProcessInfo &info)
{ {
AU_LOCK_GUARD(this->mutex);
info.type = ETickType::eRerun; info.type = ETickType::eRerun;
auto uTickCount = ++this->uTickCount; auto uTickCount = ++this->uTickCount;
@ -68,13 +71,26 @@ namespace Aurora::Async
info.reschedSteadyClockAbsNs = this->uNextTickTime; info.reschedSteadyClockAbsNs = this->uNextTickTime;
if (this->pCallback->OnTick(uTickCount, uDelta, this->uLastTickTime)) if (!this->pCallback)
{
return;
}
try
{
if (this->pCallback->OnTick(uTickCount, uDelta, this->uLastTickTime))
{
info.type = ETickType::eSchedule;
}
else
{
info.type = ETickType::eFinished;
}
}
catch (...)
{ {
info.type = ETickType::eSchedule; info.type = ETickType::eSchedule;
} SysPushErrorCatch();
else
{
info.type = ETickType::eFinished;
} }
} }

View File

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