Linux使用wake_up_interruptible()唤醒注册到等待队列上的进程
(2013-02-18 22:24:53)
标签:
linux嵌入式it |
功能:唤醒注册到等待队列上的进程
原型:
原型:
说明:
变量:
q :
在驱动中实现读取操作时,使用了
- wait_event_interruptible(button_waitq, ev_press);
- ev_press =
1;
//表示中断发生了 -
wake_up_interruptible(&button_waitq);
//唤醒休眠的进程
查找资料,阅读源代码。
- #define wait_event_interruptible(wq,
condition)
\ -
({
\ -
int __ret = 0; \ -
if (!(condition)) \ -
__wait_event_interruptible(wq, condition, __ret);\ -
__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)
- //唤醒 q 指定的注册在等待队列上的进程。该函数不能直接的立即唤醒进程,而是由调度程序转换上下文,调整为可运行状态。
- wake_up_interruptible (wait_queue_head_t *q);
不知道内核这样设计是基于什么原因?