regarding __wait_event_interruptible

Amit Nagal helloin.amit at gmail.com
Sat Jul 2 08:43:38 EDT 2011


On Fri, Jul 1, 2011 at 5:43 PM, Amit Nagal <helloin.amit at gmail.com> wrote:
> 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
>

Reframing the above question , what i want to ask is while waiting for
wake up events or signals in a loop ,
do we need to call prepare_to_wait  in every iteration of the loop (case 1 ) or
we should call prepare_to_wait  once only before entring the loop
and after schedule call returns set the current state =
TASK_INTERRUPTIBE (case 2) .

both cases are detailed below :

case 1 :

for(;;){
prepare_to_wait( &wq , &wait , TASK_INTERRUPTIBLE )
if(condition) break ;

if(! signal_pending ) {
    schedule();
    continue ;
}

ret = -ERESTARTSYS;
  break;

}

finish_to_wait(&wq , &wait ) ;

case 2 :

prepare_to_wait( &wq , &wait , TASK_INTERRUPTIBLE )

for(;;){
if(condition) break ;

if(! signal_pending ) {
    schedule();
    set_current_state(TASK_INTERRUPTIBLE);
    continue ;
}

ret = -ERESTARTSYS;
  break;

}

finish_to_wait(&wq , &wait ) ;

please let me know whether implementing wait as in case 2 is right approach ?

Regards
Amit Nagal



More information about the Kernelnewbies mailing list