linux schedule and queue
来源:互联网 发布:java元注解 编辑:程序博客网 时间:2024/04/26 04:32
http://blog.sina.com.cn/s/blog_78d30f6b0102uyaf.html
http://www.xuebuyuan.com/1198936.html
http://www.360doc.com/content/13/0411/11/11645800_277544630.shtml
1.使用内核提供的共享队列
#include<linux/module.h>#include<linux/init.h>#include<linux/kernel.h>#include<linux/types.h>#include<linux/kthread.h>#include<linux/wait.h>#include<linux/string.h>#include<linux/sysctl.h>#include<linux/workqueue.h>static void defense_work_handler(struct work_struct *work);static DECLARE_DELAYED_WORK(defense_work, defense_work_handler);static void defense_work_handler(struct work_struct *work){ printk(KERN_INFO "defense_work_handler function.\n"); schedule_delayed_work(&defense_work, msecs_to_jiffies(5000));}static int __init main_init(void){ schedule_delayed_work(&defense_work, 1 * HZ); return 0;}static void __exit main_exit(void){ cancel_delayed_work_sync(&defense_work);}module_init(main_init);module_exit(main_exit);MODULE_LICENSE("GPL");
2.使用自定义工作队列
#include<linux/kernel.h>#include<linux/module.h>#include<linux/proc_fs.h>#include<linux/workqueue.h>#include<linux/sched.h>#include<linux/init.h>#include<linux/interrupt.h>#include<linux/delay.h>struct workqueue_struct *test_workqueue;struct delayed_work test_delaywork;void delay_func(struct work_struct *work){ printk(KERN_ALERT "delay_func() called...\n"); queue_delayed_work(test_workqueue, &test_delaywork, msecs_to_jiffies(5000));}static int __init example_init(void){ test_workqueue = create_workqueue("test_workqueue"); if (!test_workqueue) return 1; INIT_DELAYED_WORK(&test_delaywork, delay_func); queue_delayed_work(test_workqueue, &test_delaywork, 500); return 0;}static void __exit example_exit(void){ int ret; ret = cancel_delayed_work(&test_delaywork); flush_workqueue(test_workqueue); destroy_workqueue(test_workqueue); printk(KERN_INFO "Goodbye! ret=%d\n", ret);}module_init(example_init);module_exit(example_exit);MODULE_LICENSE("GPL");
0 0
- linux schedule and queue
- URAL 2026 Dean and Schedule 贪心、双端队列(deque)、队列(queue)
- Linux Wait Queue and Completion Summary
- linux schedule
- LINUX内核部件之阻塞wait queue and poll
- articles about network queue and linux sysctl parameters
- schedule mm_struct and CPU register
- C - Dean and Schedule --贪心
- linux schedule() 流程图
- linux 调度 schedule分析
- linux schedule() 流程图
- linux io schedule: CFQ
- Linux schedule introduction
- linux schedule 数据结构
- Linux schedule 6、Cgoup
- Linux schedule (目录)
- gotoAndPlay and the queue
- stack and queue
- 一个关于int值越界的问题
- 线程创建与C/C++运行时库函数的笔记
- C语言--指针与数组
- 一篇很好的Touch事件分发机制讲解
- 展示两种WCF服务通信方式
- linux schedule and queue
- MySql优化之my.ini 中文配置详解
- usb hub
- 增量数据下发整合成全量表的程序分享
- 怎样花两年时间去面试一个人
- Spring
- log过滤器的运用
- # 关于DataURL Blob File FileReader createObjectURL canvas及其相互转化
- Windows转战Ubuntu