- 论坛徽章:
- 0
|
请教大家几个问题,先在此谢过了!!!
/* wait_event_interruptible 宏 */
#define wait_event_interruptible(wq, condition) \
({ \
int __ret = 0; \
if (!(condition)) \
__wait_event_interruptible(wq, condition, __ret); \
__ret; \
})
当进程执行(进入)wait_event_interruptible宏时,首先检查一遍condition是否为真,如果为真,直接跳出wait_event_interruptible 宏,继续向下执行。
当condition为假时,进入__wait_event_interruptible:
/* __wait_event_interruptible 宏 */
#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)
一,进入__wait_event_interruptible后,首先定义并初始化一个wait_queue_t变量__wait,其中数据为当前进程current,并把__wait入队。
接着进入for死循环中:
在for循环中,__wait_event_interruptible将本进程置为可中断的挂起状态,之后检查condition,如果condition为真,跳出for循环,执行finish_wait,在finish_wait函数中,会将当前进程状态设为运行态,之后跳出wait_event_interruptible。进程继续向下执行。
二,如果进入for循环后,第一次检查condition为假时,
进入第二个if语句,调用schedule,将位于TASK_INTERRUPTIBLE状态的当前进程从runqueue
队列中删除,而从runqueue队列中删除的结果是,当前这个进程将不再参与调度,(schedule()会调度别的进程运行,这个进程睡去,因wake_up_interruptible或信号被唤醒时才从schedule()返回)然后进程就停在这了!??等待唤醒,即等待调用wake_up。
如果不在其他函数内(中断处理程序)调用wake_up,那当前进程就死在这了????
如果中断处理程序中调用wake_up(将这个进程重新放入这个runqueue队列中),那当前进程就等待被调度,被调度之后,即执行continue。继续for循环。
我有几个疑问要请教:
一,我以上所述是否正确???
二,检查condition是否为真是在调用wake_up之后执行一次是吗?也就是说每wake_up一次才检测一次condition是否为真???
三,如果当前进程不被调度之后,一直没有wake_up执行,那当前进程就死在这了???
|
|