您是否需要在del_timer()之后再次调用init_timer() [英] Do you need to call init_timer() again after a del_timer()
问题描述
我有一个Linux
模块,它创建计时器,其中一些计时器可能会在其处理程序功能中再次添加自己.
I have a Linux
module which creates timers, some of which may add themselves again during their handler function.
在其他情况下,使用del_timer_sync()
删除计时器(可能在关闭计时器之前).
In some other cases, the timer is removed (perhaps before it's gone off) using del_timer_sync()
.
在那种情况下,我是否需要在下一个add_timer(
之前在结构上再次执行init_timer()
调用),还是浪费了(宝贵的)中断延迟?
In that case, do I need to do the init_timer()
call again on the struct before I next add_timer(
) or is that just a waste of (precious) interrupt latency?
推荐答案
要回答我自己的问题,我想如果我打算访问任何del_timer()或del_timer_sync()之后,确实需要在自己的结构上初始化init_timer().再次进行结构化-例如,在执行timer_pending()或在模块清理过程中执行某些操作时.
To answer my own question, I believe I do need to init_timer() my struct after any del_timer() or del_timer_sync() if I ever intend to access the struct again - for example, when doing a timer_pending() or something during module cleanup.
我认为在编写可能重复使用计时器的内核模块的情况下,最好的做法是:
I think in the case of writing a kernel module which potentially re-uses a timer, the best thing to do is:
static struct timer_list my_timer;
...
static void remove_my_timer(void)
{
if (timer_pending(&my_timer))
{
del_timer_sync(&my_timer);
init_timer(&my_timer);
}
}
static void arm_my_timer(...)
{
remove_my_timer();
my_timer.expires = ...;
my_timer.data = ...;
my_timer.function = ...;
add_timer(&my_timer);
}
...
int __init init_my_device(void)
{
...
init_timer(&my_timer);
...
}
void __exit cleanup_my_device(void)
{
...
remove_my_timer();
...
}
希望对以后的人有所帮助.
Hope that helps someone else in future.
这篇关于您是否需要在del_timer()之后再次调用init_timer()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!