code for wait_event_interruptible

北战南征 提交于 2019-12-23 03:26:11

问题


Where can I find the code for wait_event_interruptible in Kernel tree. What I can find is wait_event_interruptible is defined as __wait_event_interruptible in . But I am unable to find the code . Please help me out.

Consider a process which has gone to sleep by wait_event_interruptible. Suppose if there is an interrupt now and the interrupt handler wakes(wake_up_event_interruptible) up the sleeping process. For the process to wake up successfully should the condition given in wait_event_interruptible be true ?

Thanks


回答1:


It's in include/linux/wait.h:

#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)



回答2:


Answering your second question, yes.

Whenever an interrrupt handler (or any other thread for that matter) calls wake_up() on the waitqueue, all the threads waiting in the waitqueue are woken up and they check their conditions. Only those threads whose conditions are true continue, the rest go back to sleep. See waitqueues in LDD3.

Use ctags or cscope so that you can easily find definitions like these.



来源:https://stackoverflow.com/questions/10894113/code-for-wait-event-interruptible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!