Linux Kernel 中 Workqueue 使用系统默认队列和创建队列的方法
来源:互联网 发布:菜鸟网络盈利模式 编辑:程序博客网 时间:2024/06/06 00:55
static struct work_struct work;
{
Do something here!!
}
{
return queue_work(system_wq, work);
}
alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, ##args)
#define create_workqueue(name) \
alloc_workqueue((name), WQ_MEM_RECLAIM, 1)
#define create_freezable_workqueue(name) \
alloc_workqueue((name), WQ_FREEZABLE | WQ_UNBOUND | WQ_MEM_RECLAIM, 1)
#define create_singlethread_workqueue(name) \
alloc_workqueue((name), WQ_UNBOUND | WQ_MEM_RECLAIM, 1)
__INIT_DELAYED_WORK(_work, _func, 0)
这个问题比较有意思,写了这个例子来验证答案(例子跑在android 4.4 code base中)
sample test code:
static struct workqueue_struct *test_wq;
static void try_to_test(struct work_struct *work)
{
printk(“[bevis] :wq into \n”);
msleep(5*1000); //5s
printk(“[bevis] :wq out \n”);
}
static DECLARE_WORK(mytest_work, try_to_test);
gsensor probe function end add :
test_wq = alloc_ordered_workqueue(“test_wq”, 0); //初始化一个单独的工作队列
int a = 0;
for(a=0 ; a<3 ; a++){
printk(“[bevis] : read func (%d) before \n”,a);
queue_work(test_wq, &mytest_work); //让这个队列开始被调度
printk(“[bevis] : read func (%d) msleep 2s \n”,a);
msleep(2*1000);
printk(“[bevis] : read func (%d) after \n”,a);
}
log如下:
10-16 14:10:41.940 I/KERNEL ( 109): [ 6.954658] [bevis] : read func (0) before
10-16 14:10:41.940 I/KERNEL ( 109): [ 6.954727] [bevis] : read func (0) msleep 2s
10-16 14:10:41.940 I/KERNEL ( 109): [ 6.954742] [bevis] :wq into
10-16 14:10:43.950 I/KERNEL ( 109): [ 8.960997] [bevis] : read func (0) after
10-16 14:10:43.950 I/KERNEL ( 109): [ 8.961085] [bevis] : read func (1) before
10-16 14:10:43.950 I/KERNEL ( 109): [ 8.961155] [bevis] : read func (1) msleep 2s
10-16 14:10:45.960 I/KERNEL ( 109): [ 10.971954] [bevis] : read func (1) after
10-16 14:10:45.960 I/KERNEL ( 109): [ 10.972076] [bevis] : read func (2) before
10-16 14:10:45.960 I/KERNEL ( 109): [ 10.972132] [bevis] : read func (2) msleep 2s
10-16 14:10:46.950 I/KERNEL ( 6): [ 11.961884] [bevis] :wq out
10-16 14:10:46.950 I/KERNEL ( 6): [ 11.961953] [bevis] :wq into
10-16 14:10:47.970 I/KERNEL ( 109): [ 12.982276] [bevis] : read func (2) after
10-16 14:10:51.960 I/KERNEL ( 6): [ 16.973719] [bevis] :wq out
- Linux Kernel 中 Workqueue 使用系统默认队列和创建队列的方法
- linux 工作队列(workqueue)
- linux 工作队列workqueue
- 如何使用Linux工作队列workqueue
- linux工作队列 - workqueue总览
- linux内核中断处理的工作队列workqueue机制
- linux设备驱动下的工作队列(workqueue)
- [Linux API]linux 工作队列workqueue
- Linux工作队列workqueue实现分析
- linux内核知识之工作队列(workqueue)
- Linux工作队列workqueue实现分析
- linux kernel 工作队列
- linux kernel 工作队列
- linux kernel 工作队列
- linux kernel 工作队列
- linux kernel 工作队列
- linux kernel 工作队列
- 5-1 Linux内核中断机制(中断的申请和释放、中断低半部tasklet队列和workqueue队列、中断共享的实现)
- ubuntu下用postfix搭建邮件服务器
- tomcat6 中context配置,使用tomcat 数据源
- javaScript键盘触发事件(仅个人学习)
- 堆--神奇的优先队列
- Windows下使用命令行查看端口号被哪个进程占用
- Linux Kernel 中 Workqueue 使用系统默认队列和创建队列的方法
- ExtJs框架 文件上传
- Javascript 的函数式对象 利用闭包模拟类的静态变量和方法
- 只有五行的算法--Floyd--Warshall
- linux基础编程 多线程中的互斥锁 pthread_mutex_lock
- LeetCode 69. Sqrt(x)(开平方根)
- 关于input style属性兼容性问题
- MapReduce:详细介绍Shuffle的执行过程
- 策略模式(参考仿造《Head First设计模式》)