【问题标题】:Kernel module, multiple high resolution timers内核模块,多个高分辨率定时器
【发布时间】:2015-02-08 07:11:14
【问题描述】:

我想实现多个 hrtimer,但我不确定如何将所有这些与相同的回调函数一起使用。例如,我有 my_struct 类型的数组,其中一个字段是 struct hrtimer。

当我进入回调函数时,如何判断数组的哪个元素在调用它?

【问题讨论】:

    标签: linux linux-kernel linux-device-driver


    【解决方案1】:

    使用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;
        ...
    }
    

    【讨论】:

    • 这是完美的。谢谢! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 2011-10-31
    • 2014-04-27
    • 2010-09-14
    • 1970-01-01
    相关资源
    最近更新 更多