forked from backup/30dayMakeOS
取消定时器
This commit is contained in:
@@ -36,6 +36,7 @@ struct TIMER *timer_alloc(void)
|
||||
for (i = 0; i < MAX_TIMER; i++) {
|
||||
if (timerctl.timers0[i].flags == 0) {
|
||||
timerctl.timers0[i].flags = TIMER_FLAGS_ALLOC;
|
||||
timerctl.timers0[i].flags2 = 0;
|
||||
return &timerctl.timers0[i];
|
||||
}
|
||||
}
|
||||
@@ -116,3 +117,53 @@ void inthandler20(int *esp)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int timer_cancel(struct TIMER *timer)
|
||||
{
|
||||
int e;
|
||||
struct TIMER *t;
|
||||
e = io_load_eflags();
|
||||
io_cli(); /*在设置过程中禁止改变定时器状态*/
|
||||
if (timer->flags == TIMER_FLAGS_USING) { /*是否需要取消?*/
|
||||
if (timer == timerctl.t0) {
|
||||
/*第一个定时器的取消处理*/
|
||||
t = timer->next;
|
||||
timerctl.t0 = t;
|
||||
timerctl.next = t->timeout;
|
||||
} else {
|
||||
/*非第一个定时器的取消处理*/
|
||||
/*找到timer前一个定时器*/
|
||||
t = timerctl.t0;
|
||||
for (;;) {
|
||||
if (t->next == timer) {
|
||||
break;
|
||||
}
|
||||
t = t->next;
|
||||
}
|
||||
t->next = timer->next;
|
||||
/*将之前“timer的下一个”指向“timer的下一个”*/
|
||||
}
|
||||
timer->flags = TIMER_FLAGS_ALLOC;
|
||||
io_store_eflags(e);
|
||||
return 1; /*取消处理成功*/
|
||||
}
|
||||
io_store_eflags(e);
|
||||
return 0; /*不需要取消处理*/
|
||||
}
|
||||
|
||||
void timer_cancelall(struct FIFO32 *fifo)
|
||||
{
|
||||
int e, i;
|
||||
struct TIMER *t;
|
||||
e = io_load_eflags();
|
||||
io_cli(); /*在设置过程中禁止改变定时器状态*/
|
||||
for (i = 0; i < MAX_TIMER; i++) {
|
||||
t = &timerctl.timers0[i];
|
||||
if (t->flags != 0 && t->flags2 != 0 && t->fifo == fifo) {
|
||||
timer_cancel(t);
|
||||
timer_free(t);
|
||||
}
|
||||
}
|
||||
io_store_eflags(e);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user