下面把API罗列一下,每个函数的解释可参考之前版本的介绍或者之后的实作:
1
2
3
4
5
6
7
8
9
10
11
|
INIT_WORK(
struct
work_struct *work, work_func_t func);
INIT_DELAYED_WORK(
struct
delayed_work *work, work_func_t func);
int
schedule_work(
struct
work_struct *work);
int
schedule_delayed_work(
struct
delayed_work *work, unsigned
long
delay);
struct
workqueue_struct *create_workqueue(
const
char
*name);
int
queue_work(
struct
workqueue_struct *wq,
struct
work_struct *work);
int
queue_delayed_work(
struct
workqueue_struct *wq,
struct
delayed_work *work, unsigned
long
delay);
void
flush_scheduled_work(
void
);
void
flush_workqueue(
struct
workqueue_struct *wq);
int
cancel_delayed_work(
struct
delayed_work *work);
void
destroy_workqueue(
struct
workqueue_struct *wq);
|
其中,1、2、4、7和以前略有区别,其他用法完全一样。
在对实时要求比较高的情况下,我们才会考虑在中断中采用tasklet、软中断;
而在一般的情况下,我们都是采用工作队列的方式来处理中断下半部,我们重点就来探讨一下工作队列的用法。
1.采用cpu自带的工作队列
1)静态创建工作
#define DECLARE_WORK(n, f)
#define DECLARE_DELAYED_WORK(n, f) n表示name,f表示func
2)代码执行时动态创建
INIT_WORK(
struct
work_struct *work, work_func_t func);
INIT_DELAYED_WORK(
struct
delayed_work *work, work_func_t func);
3)调度工作队列
int
schedule_work(
struct
work_struct *work);
int
schedule_delayed_work(
struct
delayed_work *work, unsigned
long
delay);
2.自己创建工作队列
1)静态创建工作
#define DECLARE_WORK(n, f)
#define DECLARE_DELAYED_WORK(n, f) n表示name,f表示func
例子: static void ft5316_work(struct work_struct *work);
static DECLARE_DELAYED_WORK(tp_work,ft5316_work);
2)代码执行时动态创建
INIT_WORK(
struct
work_struct *work, work_func_t func);
INIT_DELAYED_WORK(
struct
delayed_work *work, work_func_t func);
3)创建自己的工作队列
static struct workqueue_struct *ft5316_wq;
ft5316_wq = create_workqueue("ft5316_wq");
4)调度自己的工作队列
int
queue_work(
struct
workqueue_struct *wq,
struct
work_struct *work);
int
queue_delayed_work(
struct
workqueue_struct *wq,
struct
delayed_work *work, unsigned
long
delay);
queue_delayed_work(ft5316_wq ,&tp_work,msecs_to_jiffies(0));