zoukankan      html  css  js  c++  java
  • 工作队列

    一、介绍

    在中断处理中,经常用到工作队列,这样便能缩短中断处理时的时间

    中断中通过调用schedule_work(work)来通知内核线程,然后中断结束后,再去继续执行work对应的func函数

    二、示例

    当中断来了,立马调用schedule_work(work),然后退出。中断结束后,内核便会调用_work对应的func函数,最后才来读取按键值,上报按键值,这样就大大缩短了中断处理时间

    三、常用函数

    1、INIT_WORK函数

    INIT_WORK(work, func);
    

    其中参数1是个work_struct结构体,参数2是个函数名,通过INIT_WORK将work_struct与一个函数建立起来.

    其中work_struct结构体定义如下所示:

    struct work_struct {
             atomic_long_t data;                       
             struct list_head entry;                     
             work_func_t func;                            //函数指针,指向func函数
    #ifdef CONFIG_LOCKDEP
             struct lockdep_map lockdep_map;
    #endif
    };
    

    2、schedule_work函数

    schedule_work(work);
    

    通知内核线程,在后续的时间里,系统将会自动调用work结构体对应的func函数。

    3、cancel_work_sync函数。

    bool cancel_work_sync(struct work_struct *work);
    

    取消work结构体对应的func函数,一般在exit中使用

     

      

  • 相关阅读:
    D2. Remove the Substring (hard version)(思维 )
    暑假集训
    AcWing:167. 木棒(dfs + 剪枝)
    AcWing:109. 天才ACM(倍增 + 归并排序)
    AcWing:99. 激光炸弹(前缀和)
    B. Interesting Array(线段树)
    Best Reward HDU
    G. Swapping Places
    How many HDU
    GSS4&&花仔游历各国
  • 原文地址:https://www.cnblogs.com/yuanqiangfei/p/15206896.html
Copyright © 2011-2022 走看看