From c02fdb4a9238a282479161226584ba0845703ae9 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 24 Nov 2022 13:06:26 +0800 Subject: [PATCH] add is_destory --- a8/timer_attacher.cc | 3 ++- a8/timer_attacher.h | 3 +++ a8/xtimer.cc | 6 +++--- a8/xtimer.h | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/a8/timer_attacher.cc b/a8/timer_attacher.cc index c3dd76b..bd3f8df 100644 --- a/a8/timer_attacher.cc +++ b/a8/timer_attacher.cc @@ -34,6 +34,7 @@ namespace a8 XTimerAttacher::~XTimerAttacher() { + is_destory_ = true; ClearTimerList(); } @@ -43,7 +44,7 @@ namespace a8 struct list_head* n = nullptr; list_for_each_safe(pos, n, &timer_list_){ xtimer_list* tmp_timer = xtimer->GetTimerByAttach(pos); - xtimer->DeleteTimer(tmp_timer); + xtimer->DeleteTimer(tmp_timer, is_destory_); } } diff --git a/a8/timer_attacher.h b/a8/timer_attacher.h index 5b900f3..c047a14 100644 --- a/a8/timer_attacher.h +++ b/a8/timer_attacher.h @@ -24,6 +24,9 @@ namespace a8 XTimerAttacher(); ~XTimerAttacher(); void ClearTimerList(); + + private: + bool is_destory_ = false; }; } diff --git a/a8/xtimer.cc b/a8/xtimer.cc index 2dff0cd..aedecb6 100644 --- a/a8/xtimer.cc +++ b/a8/xtimer.cc @@ -248,7 +248,7 @@ namespace a8 } } - void XTimer::DeleteTimer(xtimer_list* timer) + void XTimer::DeleteTimer(xtimer_list* timer, bool is_destory) { if (!timer) { abort(); @@ -257,7 +257,7 @@ namespace a8 base_->running_timer = nullptr; } if (timer->timer_after_func) { - timer->timer_after_func(timer->param); + timer->timer_after_func(timer->param, is_destory); } DetachTimer(timer); if (!list_empty(&timer->attach_entry)) { @@ -356,7 +356,7 @@ namespace a8 } AddToFreeList(timer); if (timer->timer_after_func) { - timer->timer_after_func(timer->param); + timer->timer_after_func(timer->param, false); } } break; diff --git a/a8/xtimer.h b/a8/xtimer.h index bbfdcdb..00f0bd6 100644 --- a/a8/xtimer.h +++ b/a8/xtimer.h @@ -9,7 +9,7 @@ struct xtvec_base; namespace a8 { typedef void (*XTimerFunc)(const a8::XParams& param); - typedef void (*XTimerAfterFunc)(const a8::XParams& param); + typedef void (*XTimerAfterFunc)(const a8::XParams& param, bool is_destory); typedef long long (*XGetTickCountFunc)(void*); typedef struct list_head XTimerDestoryHandle; struct XTimerPtr; @@ -41,7 +41,7 @@ namespace a8 void ModifyTimer(xtimer_list* timer, int expire_time); void ModifyTimer(std::weak_ptr& ptr, int expire_time); //删除定时器 - void DeleteTimer(xtimer_list* timer); + void DeleteTimer(xtimer_list* timer, bool is_destory = false); //通过关联的list_head获取定时器对象 xtimer_list* GetTimerByAttach(list_head* attach_entry); //获取定时器关联参数