1、定义数据结构
struct delayed_work work;
struct workqueue_struct *wq;
2、编写要被提交到工作队列中的函数,函数原形如下:
typedef void(*work_func_t)(struct work_struct *work);
3、创建一个专用的内核线程来执行提交到工作队列中的函数
wq = create_singlethread_workqueue(const char *name);
4、初始化数据结构
INIT_DELAYED_WORK(struct delayed_work *work, work_func_t func);
5、将任务提交到工作队列
queue_delayed_work(struct workqueue_struct *wq, struct delayed_work* work, unsigned long timeout);
6、删除提交到工作队列中的任务
int cancel_delayed_work(struct delayed_work *work);
7、刷新工作队列
void flush_workqueue(struct workqueue_struct *wq);
8、释放相关资源
void destory_workqueue(struct workqueue_struct *wq);
其中,第6、7、8项不是必须的,根据实际情景选择是否使用。