kernel tasklets, and work queues
来源:互联网 发布:网络防雷保护器 编辑:程序博客网 时间:2024/06/01 10:34
Simple example of a tasklet in the context of a kernel module:
#include <linux/kernel.h>#include <linux/module.h>#include <linux/interrupt.h>MODULE_LICENSE("GPL");char my_tasklet_data[]="my_tasklet_function was called";/* Bottom Half Function */void my_tasklet_function( unsigned long data ){ printk( "%s\n", (char *)data ); return;}DECLARE_TASKLET( my_tasklet, my_tasklet_function, (unsigned long) &my_tasklet_data );int init_module( void ){ /* Schedule the Bottom Half */ tasklet_schedule( &my_tasklet ); return 0;}void cleanup_module( void ){ /* Stop the tasklet before we exit */ tasklet_kill( &my_tasklet ); return;}
Simple work queue example
#include <linux/kernel.h>#include <linux/module.h>#include <linux/workqueue.h>MODULE_LICENSE("GPL");static struct workqueue_struct *my_wq;typedef struct { struct work_struct my_work; int x;} my_work_t;my_work_t *work, *work2;static void my_wq_function( struct work_struct *work){ my_work_t *my_work = (my_work_t *)work; printk( "my_work.x %d\n", my_work->x ); kfree( (void *)work ); return;}
int init_module( void ){ int ret; my_wq = create_workqueue("my_queue"); if (my_wq) { /* Queue some work (item 1) */ work = (my_work_t *)kmalloc(sizeof(my_work_t), GFP_KERNEL); if (work) { INIT_WORK( (struct work_struct *)work, my_wq_function ); work->x = 1; ret = queue_work( my_wq, (struct work_struct *)work ); } /* Queue some additional work (item 2) */ work2 = (my_work_t *)kmalloc(sizeof(my_work_t), GFP_KERNEL); if (work2) { INIT_WORK( (struct work_struct *)work2, my_wq_function ); work2->x = 2; ret = queue_work( my_wq, (struct work_struct *)work2 ); } } return 0;}
void cleanup_module( void ){ flush_workqueue( my_wq ); destroy_workqueue( my_wq ); return;}
0 0
- kernel tasklets, and work queues
- Linked Lists and Work Queues
- ch7-deferred work tasklets
- How do durable queues and topics work
- work queues
- Soft Irqs And Tasklets
- softirq and tasklets
- Java theory and practice: Thread pools and work queues
- Linux Kernel之Deferred work(Softirq、tasklet、Work queues)来龙去脉浅析
- What’s different between deferrable functions and work queues
- 四、rabbitMQ Work Queues
- RabbitMQ之Work Queues
- RabbitMQ Work queues
- rabbitmq 教程 二 Work Queues
- rabbitmq学习2:Work Queues
- RabbitMQ 入门三(Work Queues)
- rabbitmq学习2:Work Queues
- rabbitmq学习2:Work Queues
- 通过http post发送json数据
- 图片加水印c#
- POJ1837 动态规划 (01背包)
- Activity 自定义dialog (自定义layout)
- mysql 存储过程
- kernel tasklets, and work queues
- Android Shape自定义纯色圆角按钮
- SQL Server调优系列进阶篇(如何维护数据库索引)
- Eclipse 快捷键 查找关联文件
- Cocos2dx-Lua:360滑动操作杆
- 听刘老讲产品经理第一课
- scala入门-04 类(class)的使用
- IOS Tab bar Item的设计
- 用python的BeautifulSoup分析html