code for wait_event_interruptible

牧云@^-^@ 提交于 2019-12-06 16:49:04

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)

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.

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