【发布时间】:2015-02-08 07:11:14
【问题描述】:
我想实现多个 hrtimer,但我不确定如何将所有这些与相同的回调函数一起使用。例如,我有 my_struct 类型的数组,其中一个字段是 struct hrtimer。
当我进入回调函数时,如何判断数组的哪个元素在调用它?
【问题讨论】:
标签: linux linux-kernel linux-device-driver
我想实现多个 hrtimer,但我不确定如何将所有这些与相同的回调函数一起使用。例如,我有 my_struct 类型的数组,其中一个字段是 struct hrtimer。
当我进入回调函数时,如何判断数组的哪个元素在调用它?
【问题讨论】:
标签: linux linux-kernel linux-device-driver
使用container_of 宏:
struct my_struct {
int my_something;
struct hrtimer my_timer;
...
};
enum hrtimer_restart my_callback(struct hrtimer *hrtimer)
{
struct my_struct my = container_of(hrtimer, struct my_struct, my_timer);
my->my_something = 42;
...
}
【讨论】: