regarding __wait_event_interruptible

Amit Nagal helloin.amit at gmail.com
Fri Jul 1 08:13:57 EDT 2011


Hi ,

__wait_event_interruptible  is defined in include/linux/wait.h as :

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

here , can  i be guided why in every for loop iteration , we need to
call prepare_to_wait ?

instead why not prepare_to_wait() be used once only like finish_wait()
above and after schedule() call returns ,
set the current state = TASK_INTERRUPTIBLE (before continue statement
) something like below :

#define __wait_event_interruptible(wq, condition, ret)                  \
do {                                                                    \
        DEFINE_WAIT(__wait);                                            \
        prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);      	\
                                                                        \
        for (;;) {                                                      \

                if (condition)                                          \
                        break;                                          \
                if (!signal_pending(current)) {                         \
                        schedule();                                     \
	        set_current_state(TASK_INTERRUPTIBLE)		\
                        continue;                                       \
                }                                                       \
                ret = -ERESTARTSYS;                                     \
                break;                                                  \
        }                                                               \
        finish_wait(&wq, &__wait);                                      \
} while (0)

kindly share facts related to above .

Regards
Amit Nagal



More information about the Kernelnewbies mailing list