“
一个处于pending状态的定时器是处在处理器的定时器管理队列中正等待被调度执行的定时器对象
。
timer_pending是用来判断一个处在定时器管理队列中的定时器 对象 是否 已经被 调度执行
add_timer只是把一个定时器对象加入到内核的管理队列,但是何时执行实际上由时钟中断(更确切地,是内核在时钟中断的softirq部分才开始扫描定时器管理队列),一个定时器对象pending意味着它的回调函数 尚未 被调度执行,而一旦一个定时器对象 被调度执行 ,之后它将被从定时器管理队列中摘除,除非 它再次 被提交。
void add_timer(struct timer_list *timer)
{
BUG_ON(timer_pending(timer));
mod_timer(timer, timer->expires);//修改定时的时间.
}
{
BUG_ON(timer_pending(timer));
mod_timer(timer, timer->expires);//修改定时的时间.
}
* return value: 1 if the timer is pending, 0 if not.
//没有被调度执行,返回0. 正在被吊住执行返回1.
static inline int timer_pending(const struct timer_list * timer)
{
return timer->entry.next != NULL;
}
{
return timer->entry.next != NULL;
}
//mod_time()激活定时器,激活没有激活的定事情,返回0.激活已经激活的返回0.
* mod_timer() is a more efficient way to update the expire field of an
* active timer (if the timer is inactive it will be activated)
* active timer (if the timer is inactive it will be activated)
* The function returns whether it has modified a pending timer or not.
* (ie. mod_timer() of an inactive timer returns 0, mod_timer() of an
* active timer returns 1.)
* (ie. mod_timer() of an inactive timer returns 0, mod_timer() of an
* active timer returns 1.)
struct timer_list {
struct list_head entry;
unsigned long expires;
struct tvec_base *base;
void (*function)(unsigned long);
unsigned long data;
struct list_head entry;
unsigned long expires;
struct tvec_base *base;
void (*function)(unsigned long);
unsigned long data;
}
init_timer(&timer); 这个时候就是初始化entry == NULL