1

我在哪里可以找到内核树中 wait_event_interruptible 的代码。我能找到的是 wait_event_interruptible 被定义为 __wait_event_interruptible 在 . 但我找不到代码。请帮帮我。

考虑一个通过 wait_event_interruptible 进入睡眠状态的进程。假设现在有中断并且中断处理程序唤醒(wake_up_event_interruptible)休眠进程。为了让进程成功唤醒,wait_event_interruptible 中给出的条件是否应该为真?

谢谢

4

2 回答 2

4

它在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)
于 2012-06-05T08:51:55.660 回答
0

回答你的第二个问题,是的。

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.

于 2012-06-07T02:10:48.933 回答