关于__mod_timer函数(linux/kernel/timer.c中定义的)的问题
关于__mod_timer函数(kernel-2.6.13/timer.c中定义的)的问题
函数代码如下:
int __mod_timer(struct timer_list *timer, unsigned long expires)
{
timer_base_t *base;
tvec_base_t *new_base;
unsigned long flags;
int ret = 0;
BUG_ON(!timer->function);
check_timer(timer);
base = lock_timer_base(timer, &flags);
if (timer_pending(timer)) {
detach_timer(timer, 0);
ret = 1;
}
new_base = &__get_cpu_var(tvec_bases);
if (base != &new_base->t_base) {
/*
* We are trying to schedule the timer on the local CPU.
* However we can't change timer's base while it is running,
* otherwise del_timer_sync() can't detect that the timer's
* handler yet has not finished. This also guarantees that
* the timer is serialized wrt itself.
*/
if (unlikely(base->running_timer == timer)) {
/* The timer remains on a former base */
new_base = container_of(base, tvec_base_t, t_base);
} else {
/* See the comment in lock_timer_base() */
timer->base = NULL;
spin_unlock(&base->lock);
spin_lock(&new_base->t_base.lock);
timer->base = &new_base->t_base;
}
}
timer->expires = expires;
internal_add_timer(new_base, timer);
spin_unlock_irqrestore(&new_base->t_base.lock, flags);
return ret;
}
哪位大侠帮解释一下:“if (unlikely(base->running_timer == timer)) {
/* The timer remains on a former base */
new_base = container_of(base, tvec_base_t, t_base);
} ”这一段是什么意思?为什么要这样做?还有这一句上面的英文注释是什么意思?多谢!!!