1
This commit is contained in:
parent
806ec31e24
commit
2964212b5f
@ -14,6 +14,7 @@ namespace a8
|
||||
};
|
||||
|
||||
typedef std::function<void(const a8::Args&)> CommonCbProc;
|
||||
typedef std::weak_ptr<struct XTimerPtr> XTimerWp;
|
||||
|
||||
const int INVALID_FD = -1;
|
||||
const int INVALID_SOCKET = -1;
|
||||
|
135
a8/xtimer.cc
135
a8/xtimer.cc
@ -397,11 +397,6 @@ namespace a8
|
||||
delete node;
|
||||
}
|
||||
|
||||
void XTimer::DeleteCurrentTimer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool XTimer::IsRunningTimer()
|
||||
{
|
||||
|
||||
@ -442,68 +437,6 @@ namespace a8
|
||||
free_timers(&base_->free_timer);
|
||||
}
|
||||
|
||||
void XTimer::UpdateTimer()
|
||||
{
|
||||
struct xtvec_base *base = base_;
|
||||
while (get_tick_count_func_(context_) >= base->timer_tick) {
|
||||
struct list_head work_list;
|
||||
struct list_head *head = &work_list;
|
||||
int index = base->timer_tick & TVR_MASK;
|
||||
|
||||
if (!index &&
|
||||
(!Cascade(base, &base->tv2, INDEX(0))) &&
|
||||
(!Cascade(base, &base->tv3, INDEX(1))) &&
|
||||
!Cascade(base, &base->tv4, INDEX(2))) {
|
||||
Cascade(base, &base->tv5, INDEX(3));
|
||||
}
|
||||
++base->timer_tick;
|
||||
list_replace_init(base->tv1.vec + index, &work_list);
|
||||
while (!list_empty(head)) {
|
||||
struct xtimer_list *timer;
|
||||
timer = list_first_entry(head, struct xtimer_list,entry);
|
||||
base->running_timer = timer;
|
||||
if (timer->cb) {
|
||||
timer->cb(TIMER_EXEC_EVENT, nullptr);
|
||||
}
|
||||
if (base_->running_timer) {
|
||||
switch (timer->timer_type) {
|
||||
case 1:
|
||||
case 2: //循环类定时 fixed timer也是循环定时器
|
||||
{
|
||||
if (timer->timer_type == 2) {
|
||||
timer->fixed_timer_execute_times++;
|
||||
}
|
||||
#if 0
|
||||
ModifyTimer(timer, timer->expire_time);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default: //deadline timer
|
||||
{
|
||||
DetachTimer(timer);
|
||||
if (!list_empty(&timer->attach_entry)) {
|
||||
list_del_init(&timer->attach_entry);
|
||||
}
|
||||
while (!list_empty(&timer->destory_handle_list)) {
|
||||
XTimerDestoryHandleNode* node = list_first_entry(&timer->destory_handle_list,
|
||||
XTimerDestoryHandleNode,
|
||||
entry);
|
||||
list_del_init(&node->entry);
|
||||
node->cb(timer);
|
||||
delete node;
|
||||
}
|
||||
AddToFreeList(base_, timer);
|
||||
if (timer->cb) {
|
||||
timer->cb(TIMER_DELETE_EVENT, nullptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
base->running_timer = nullptr;
|
||||
}
|
||||
#endif
|
||||
void XTimer::SetTimeout(int time, TimerCb cb)
|
||||
{
|
||||
@ -580,4 +513,72 @@ namespace a8
|
||||
|
||||
}
|
||||
|
||||
void XTimer::UpdateTimer()
|
||||
{
|
||||
struct xtvec_base *base = base_;
|
||||
while (get_tick_count_func_(context_) >= base->timer_tick) {
|
||||
struct list_head work_list;
|
||||
struct list_head *head = &work_list;
|
||||
int index = base->timer_tick & TVR_MASK;
|
||||
|
||||
if (!index &&
|
||||
(!Cascade(base, &base->tv2, INDEX(0))) &&
|
||||
(!Cascade(base, &base->tv3, INDEX(1))) &&
|
||||
!Cascade(base, &base->tv4, INDEX(2))) {
|
||||
Cascade(base, &base->tv5, INDEX(3));
|
||||
}
|
||||
++base->timer_tick;
|
||||
list_replace_init(base->tv1.vec + index, &work_list);
|
||||
while (!list_empty(head)) {
|
||||
struct xtimer_list *timer;
|
||||
timer = list_first_entry(head, struct xtimer_list,entry);
|
||||
base->running_timer = timer;
|
||||
if (timer->cb) {
|
||||
timer->cb(TIMER_EXEC_EVENT, nullptr);
|
||||
}
|
||||
if (base_->running_timer) {
|
||||
switch (timer->timer_type) {
|
||||
case 1:
|
||||
case 2: //循环类定时 fixed timer也是循环定时器
|
||||
{
|
||||
if (timer->timer_type == 2) {
|
||||
timer->fixed_timer_execute_times++;
|
||||
}
|
||||
#if 0
|
||||
ModifyTimer(timer, timer->expire_time);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default: //deadline timer
|
||||
{
|
||||
DetachTimer(timer);
|
||||
if (!list_empty(&timer->attach_entry)) {
|
||||
list_del_init(&timer->attach_entry);
|
||||
}
|
||||
while (!list_empty(&timer->destory_handle_list)) {
|
||||
XTimerDestoryHandleNode* node = list_first_entry(&timer->destory_handle_list,
|
||||
XTimerDestoryHandleNode,
|
||||
entry);
|
||||
list_del_init(&node->entry);
|
||||
node->cb(timer);
|
||||
delete node;
|
||||
}
|
||||
AddToFreeList(base_, timer);
|
||||
if (timer->cb) {
|
||||
timer->cb(TIMER_DELETE_EVENT, nullptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
base->running_timer = nullptr;
|
||||
}
|
||||
|
||||
void XTimer::DeleteCurrentTimer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ namespace a8
|
||||
{
|
||||
typedef std::function<void(int, const a8::Args*)> TimerCb;
|
||||
typedef long long (*XGetTickCountFunc)(void*);
|
||||
typedef std::weak_ptr<struct XTimerPtr> XTimerWp;
|
||||
|
||||
class Attacher;
|
||||
class XTimer
|
||||
|
Loading…
x
Reference in New Issue
Block a user