Linux kernel 中使用 wait_event_interruptible(wq, condition) 使进程睡眠
来源:互联网 发布:王珊数据库第五版 编辑:程序博客网 时间:2024/06/06 13:14
wait_event_interruptible(wq, condition) 修改当前进程为TASK_INTERRUPTIBLE状态,并把进程添加到等待队列wq中, 意味着该进程要等到被唤醒时才能继续运行,或者被信号中断;如果没有被唤醒或者中断,它会一直等下去。
wait_event_interruptible(wq, condition) 就是用来等待condition为真, condition 一般是一个表达式,每次查看condition时都可能不一样。在wait_event_interruptible(wq, condition) 中首先判断 condition 条件是否为真,如果为真,则返回 0;否则,调用 __wait_event_interruptible(wq, condtion),并把返回值保存到_ret中。
#define wait_event_timeout(wq, condition, timeout)\
({ \
long __ret = timeout;\
if (!(condition)) \
__wait_event_timeout(wq, condition, __ret);\
__ret; \
})
__wait_event_interruptible(wq, condition, ret) 也是一个宏,定义如下
#define __wait_event_interruptible(wq, condition, ret)\
do { \
DEFINE_WAIT(__wait);\
\
for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);\
if (condition)\
break; \
if (!signal_pending(current)) {\
schedule(); \
continue; \
} \
ret = -ERESTARTSYS;\
break; \
} \
finish_wait(&wq, &__wait);\
} while (0)
其中,prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE) 先把进程放入等待队列wq中,然后把进程状态设备 TASK_INTERRUTIBLE。检查 condition 是否为真,为真则中断循环。检查是否有没有处理的信号, 如果没有,则调用schedule(),让出CPU。
- Linux kernel 中使用 wait_event_interruptible(wq, condition) 使进程睡眠
- 关于函数wait_event_interruptible(wq, condition)
- 关于函数wait_event_interruptible(wq, condition)
- Linux kernel 进程的睡眠和唤醒
- linux命令中:wq和:wq!区别
- Linux中进程的睡眠和唤醒
- linux wait_event_interruptible()
- linux-0.11中进程睡眠函数sleep_on()解析
- Linux 0.11中进程睡眠和唤醒机制思考
- Linux睡眠唤醒机制--Kernel态
- Linux睡眠唤醒机制--Kernel态
- Linux睡眠唤醒机制--Kernel态2
- Linux睡眠唤醒机制--Kernel态
- 进程挂起wait_event_interruptible
- 进程等待-wait_event_interruptible 使用方法
- Linux进程睡眠的原则
- 内核中睡眠 - Sleeping in the kernel
- vim 中:wq和:wq的不同之处
- DB2入门操作之一
- 【2014Esri开发者大会精彩看点】Python is the language of ArcGIS
- YII中使用自带的日期插件
- objective-c中的特性
- opencv之图像轮廓提取
- Linux kernel 中使用 wait_event_interruptible(wq, condition) 使进程睡眠
- javascript【继承实现方式 】
- 罗密欧与朱丽叶的迷宫问题_dfs
- Jquery 局部刷新及 表单取值赋值 处理返回json数据 一些基本操作
- 说的好,不然做得好
- DB2入门操作之二
- 等不过如此
- 第一篇CSDN博客
- 10 款高质量的 jQuery 表单验证插件