问题
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