关于函数wait_event_interruptible(wq, condition)
来源:互联网 发布:淘宝女装进货渠道 编辑:程序博客网 时间:2024/05/19 17:11
wait_event_interruptible(wq, condition),该函数修改task的状态为TASK_INTERRUPTIBLE,意味着该进程将不会继续运行直到被唤醒,然后被添加到等待队列wq中。
在wait_event_interruptible()中首先判断condition是不是已经满足,如果条件满足则直接返回0,否则调用__wait_event_interruptible(),并用__ret来存放返回值
#define wait_event_interruptible(wq, condition) \
({ \
int __ret = 0; \
if (!(condition)) \
__wait_event_interruptible(wq, condition, __ret);\
__ret; \
})
在无限循环中,__wait_event_interruptible()将本进程置为可中断的挂起状态,反复检查condition是否成立,如果成立则退出,如果不成立则继续休眠;条件满足后,即把本进程运行状态置为运行态
,并将__wait从等待队列中清除掉,从而进程能够调度运行。如果进程当前有异步信号(POSIX的),则返回-ERESTARTSYS。
#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)
以下是在linux下OV7725驱动(s3c2440camif.c)中的一个例子
定义等待队列
wait_queue_head_t cmdqueue;(s3c2440camif.h中定义的)
初始化等待队列
static int __init camif_probe(struct platform_device *dev)
{
......
pdev->cmdcode = CAMIF_CMD_NONE;
init_waitqueue_head(&pdev->cmdqueue);
......
}
调用等待队列
static int start_capture(struct s3c2440camif_dev * pdev, int stream)
{
......
if (stream == 0)
{
pdev->cmdcode = CAMIF_CMD_STOP;
ret = wait_event_interruptible(pdev->cmdqueue, pdev->cmdcode == CAMIF_CMD_NONE);
}
return ret;
......
}
在中断处理函数中唤醒等待队列
static irqreturn_t on_camif_irq_c(int irq, void * dev)
{
......
pdev->cmdcode = CAMIF_CMD_NONE;
wake_up(&pdev->cmdqueue);
......
}
static irqreturn_t on_camif_irq_p(int irq, void * dev)
{
......
pdev->cmdcode = CAMIF_CMD_NONE;
wake_up(&pdev->cmdqueue);
......
}
在下面函数中调用start_capture()
static ssize_t camif_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
{
......
if(start_capture(pdev, 0) != 0)
{
return -ERESTARTSYS;
}
......
}
参考资料:
http://www.ibm.com/developerworks/cn/linux/kernel/sync/index.html
http://www.360doc.com/content/10/1004/12/1345608_58325218.shtml
http://my.chinaunix.net/space.php?uid=25324849&do=blog&id=187679
- 关于函数wait_event_interruptible(wq, condition)
- 关于函数wait_event_interruptible(wq, condition)
- Linux kernel 中使用 wait_event_interruptible(wq, condition) 使进程睡眠
- 关于wait_event_interruptible
- wait_event_interruptible()
- wait_event_interruptible()
- wait_event_interruptible
- wait_event_interruptible()
- wait_event_interruptible函数以及等待队列
- 关于 wait_event_interruptible() 和 wake_up()的使用
- 关于实现条件condition-get
- 关于condition variable的理解
- vim: wq
- wait_event_interruptible 使用方法
- wait_event_interruptible 使用方法
- wait_event_interruptible说明
- wait_event_interruptible 使用方法
- wait_event_interruptible 使用方法
- struts2+hibernate3.0+spring3.0整合所需包
- DB2中使用裸设备作为表空间容器
- 小马哥-----高仿红米note 刷机救砖 各种主板拆机机型图面面观
- Java多线程生成文件性能分析案例
- 单元测试工具googletest C++Test和CppUnit
- 关于函数wait_event_interruptible(wq, condition)
- 乱码比较系统的解释
- Clock Splitter+uvalive+二分
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解(二)
- g++编译命令选项
- Bugzilla
- XML简介
- Good Product Manager/Bad Product Manager 优秀的产品经理/不合格的产品经理
- MySql忘记密码的解决方法