添加time after func功能
This commit is contained in:
parent
9f43c10312
commit
1bcc249554
10
a8/timer.cc
10
a8/timer.cc
@ -205,10 +205,11 @@ namespace a8
|
|||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
timer_list* Timer::AddFixedTimer(int milli_seconds, a8::XParams param, a8::TimerFunc timer_func)
|
timer_list* Timer::AddFixedTimer(int milli_seconds, a8::XParams param, a8::TimerFunc timer_func,
|
||||||
|
a8::TimerAfterFunc timer_after_func)
|
||||||
{
|
{
|
||||||
timer_list *timer = NewTimerList();
|
timer_list *timer = NewTimerList();
|
||||||
InitTimerList(base_, timer, 2, milli_seconds, param, timer_func, nullptr);
|
InitTimerList(base_, timer, 2, milli_seconds, param, timer_func, timer_after_func);
|
||||||
ModifyTimer(timer, milli_seconds);
|
ModifyTimer(timer, milli_seconds);
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
@ -216,9 +217,10 @@ namespace a8
|
|||||||
timer_list* Timer::AddFixedTimerAndAttach(int milli_seconds,
|
timer_list* Timer::AddFixedTimerAndAttach(int milli_seconds,
|
||||||
a8::XParams param,
|
a8::XParams param,
|
||||||
a8::TimerFunc timer_func,
|
a8::TimerFunc timer_func,
|
||||||
list_head* attach_list)
|
list_head* attach_list,
|
||||||
|
a8::TimerAfterFunc timer_after_func)
|
||||||
{
|
{
|
||||||
timer_list *timer = AddFixedTimer(milli_seconds, param, timer_func);
|
timer_list *timer = AddFixedTimer(milli_seconds, param, timer_func, timer_after_func);
|
||||||
list_add_tail(&timer->attach_entry, attach_list);
|
list_add_tail(&timer->attach_entry, attach_list);
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,13 @@ namespace a8
|
|||||||
list_head* attach_list,
|
list_head* attach_list,
|
||||||
a8::TimerAfterFunc timer_after_func = nullptr);
|
a8::TimerAfterFunc timer_after_func = nullptr);
|
||||||
//添加固定时间定时器(每天,每次重启一天里可能会多次调用)
|
//添加固定时间定时器(每天,每次重启一天里可能会多次调用)
|
||||||
timer_list* AddFixedTimer(int milli_seconds, a8::XParams param, a8::TimerFunc timer_func);
|
timer_list* AddFixedTimer(int milli_seconds, a8::XParams param, a8::TimerFunc timer_func,
|
||||||
|
a8::TimerAfterFunc timer_after_func = nullptr);
|
||||||
timer_list* AddFixedTimerAndAttach(int milli_seconds,
|
timer_list* AddFixedTimerAndAttach(int milli_seconds,
|
||||||
a8::XParams param,
|
a8::XParams param,
|
||||||
a8::TimerFunc timer_func,
|
a8::TimerFunc timer_func,
|
||||||
list_head* attach_list);
|
list_head* attach_list,
|
||||||
|
a8::TimerAfterFunc timer_after_func = nullptr);
|
||||||
//修改定时器参数
|
//修改定时器参数
|
||||||
void ModifyTimer(timer_list* timer, int milli_seconds);
|
void ModifyTimer(timer_list* timer, int milli_seconds);
|
||||||
//删除定时器
|
//删除定时器
|
||||||
|
16
a8/xtimer.cc
16
a8/xtimer.cc
@ -184,7 +184,8 @@ namespace a8
|
|||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
xtimer_list* XTimer::AddRepeatTimer(int expire_time, a8::XParams param, a8::XTimerFunc timer_func)
|
xtimer_list* XTimer::AddRepeatTimer(int expire_time, a8::XParams param, a8::XTimerFunc timer_func,
|
||||||
|
a8::XTimerAfterFunc timer_after_func)
|
||||||
{
|
{
|
||||||
xtimer_list *timer = NewTimerList();
|
xtimer_list *timer = NewTimerList();
|
||||||
InitTimerList(base_,
|
InitTimerList(base_,
|
||||||
@ -194,15 +195,16 @@ namespace a8
|
|||||||
expire_time,
|
expire_time,
|
||||||
param,
|
param,
|
||||||
timer_func,
|
timer_func,
|
||||||
nullptr);
|
timer_after_func);
|
||||||
ModifyTimer(timer, expire_time);
|
ModifyTimer(timer, expire_time);
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
xtimer_list* XTimer::AddRepeatTimerAndAttach(int expire_time, a8::XParams param, a8::XTimerFunc timer_func,
|
xtimer_list* XTimer::AddRepeatTimerAndAttach(int expire_time, a8::XParams param, a8::XTimerFunc timer_func,
|
||||||
list_head* attach_list)
|
list_head* attach_list,
|
||||||
|
a8::XTimerAfterFunc timer_after_func)
|
||||||
{
|
{
|
||||||
xtimer_list* timer = AddRepeatTimer(expire_time, param, timer_func);
|
xtimer_list* timer = AddRepeatTimer(expire_time, param, timer_func, timer_after_func);
|
||||||
list_add_tail(&timer->attach_entry, attach_list);
|
list_add_tail(&timer->attach_entry, attach_list);
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
@ -299,9 +301,6 @@ namespace a8
|
|||||||
if (timer->timer_func) {
|
if (timer->timer_func) {
|
||||||
timer->timer_func(timer->param);
|
timer->timer_func(timer->param);
|
||||||
}
|
}
|
||||||
if (timer->timer_after_func) {
|
|
||||||
timer->timer_after_func(timer->param);
|
|
||||||
}
|
|
||||||
if (base_->running_timer) {
|
if (base_->running_timer) {
|
||||||
switch (timer->timer_type) {
|
switch (timer->timer_type) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -320,6 +319,9 @@ namespace a8
|
|||||||
list_del_init(&timer->attach_entry);
|
list_del_init(&timer->attach_entry);
|
||||||
}
|
}
|
||||||
AddToFreeList(timer);
|
AddToFreeList(timer);
|
||||||
|
if (timer->timer_after_func) {
|
||||||
|
timer->timer_after_func(timer->param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,11 @@ namespace a8
|
|||||||
list_head* attach_list,
|
list_head* attach_list,
|
||||||
a8::XTimerAfterFunc timer_after_func = nullptr);
|
a8::XTimerAfterFunc timer_after_func = nullptr);
|
||||||
//添加重复执行定时器(周期性定时器)
|
//添加重复执行定时器(周期性定时器)
|
||||||
xtimer_list* AddRepeatTimer(int expire_time, a8::XParams param, a8::XTimerFunc timer_func);
|
xtimer_list* AddRepeatTimer(int expire_time, a8::XParams param, a8::XTimerFunc timer_func,
|
||||||
|
a8::XTimerAfterFunc timer_after_func = nullptr);
|
||||||
xtimer_list* AddRepeatTimerAndAttach(int expire_time, a8::XParams param, a8::XTimerFunc timer_func,
|
xtimer_list* AddRepeatTimerAndAttach(int expire_time, a8::XParams param, a8::XTimerFunc timer_func,
|
||||||
list_head* attach_list);
|
list_head* attach_list,
|
||||||
|
a8::XTimerAfterFunc timer_after_func = nullptr);
|
||||||
//修改定时器参数
|
//修改定时器参数
|
||||||
void ModifyTimer(xtimer_list* timer, int expire_time);
|
void ModifyTimer(xtimer_list* timer, int expire_time);
|
||||||
//删除定时器
|
//删除定时器
|
||||||
|
Loading…
x
Reference in New Issue
Block a user