diff --git a/Source/Async/AuAsyncTimer.cpp b/Source/Async/AuAsyncTimer.cpp index 5b26a326..7ba1205d 100644 --- a/Source/Async/AuAsyncTimer.cpp +++ b/Source/Async/AuAsyncTimer.cpp @@ -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,13 +71,26 @@ namespace Aurora::Async 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; - } - else - { - info.type = ETickType::eFinished; + SysPushErrorCatch(); } } diff --git a/Source/Async/AuAsyncTimer.hpp b/Source/Async/AuAsyncTimer.hpp index 8f241141..f3e70d38 100644 --- a/Source/Async/AuAsyncTimer.hpp +++ b/Source/Async/AuAsyncTimer.hpp @@ -37,5 +37,6 @@ namespace Aurora::Async AuUInt64 uInterval {}; AuUInt64 uTickCount {}; bool bCatchUp { false }; + AuCriticalSection mutex; }; } \ No newline at end of file