regarding __wait_event_interruptible
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
On Fri, Jul 1, 2011 at 5:43 PM, Amit Nagal <helloin.amit@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
participants (1)
-
Amit Nagal