admin管理员组文章数量:1794759
【Linux内幕】schedule
1、前言
在许多情况下,设备驱动程序不需要有自己的工作队列。如果我们只是偶尔需要向队列中提交任务,则一种更简单、更有效的办法是使用内核提供的共享的默认工作队列。但是,如果我们使用了这个默认的工作队列,则应该记住我们正在和他人共享该工作队列。这意味着,我们不应该长期独占该队列,即:不能长时间休眠,而且我们的任务可能需要更长的时间才能获得处理器。
2、schedule_work使用步骤:1、定义相关数据 static struct work_struct jiq_work; 2、编写要提交到工作队列中的函数 static_void jiq_print_wq(struct work_struct *work) { … } 3、完成数据的初始化工作 INIT_WORK(&jiq_work, jiq_print_wq); 4、将任务提交到工作队列 schedule_work(&jiq_work);
3、示例 #include <Linux/module.h> #include <linux/init.h> #include <linux/workqueue.h> static struct workqueue_struct *wq = NULL; static struct work_struct work; static void work_handler(struct work_struct *data) { printk(KERN_ALERT"work handler function"); } static int __init test_init(void) { wq = create_singlethread_workqueue("my_workqueue"); if(!wq) goto err; INIT_WORK(&work, work_handler); queue_work(&work); return 0; err: return -1; } static void __exit test_exit(void) { destroy_workqueue(wq); } MODULE_LICENSE("GPL"); module_init(test_init); module_exit(rest_exit); schedule_work(&jiq_work); 4、加入讨论版权声明:本文标题:【Linux内幕】schedule 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686479455a72146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论