]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
sched: refactor wait_for_completion_timeout()
authorOleg Nesterov <oleg@tv-sign.ru>
Fri, 20 Jun 2008 14:32:20 +0000 (18:32 +0400)
committerIngo Molnar <mingo@elte.hu>
Fri, 20 Jun 2008 15:15:49 +0000 (17:15 +0200)
Simplify the code and fix the boundary condition of
wait_for_completion_timeout(,0).

We can kill the first __remove_wait_queue() as well.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
kernel/sched.c

index 577f160131bd5922da713fb69415fbc88c5aa71d..bebf9788f45ee6a4e3a08ab57ed94e1b17acf546 100644 (file)
@@ -4398,32 +4398,20 @@ do_wait_for_common(struct completion *x, long timeout, int state)
                             signal_pending(current)) ||
                            (state == TASK_KILLABLE &&
                             fatal_signal_pending(current))) {
-                               __remove_wait_queue(&x->wait, &wait);
-                               return -ERESTARTSYS;
+                               timeout = -ERESTARTSYS;
+                               break;
                        }
                        __set_current_state(state);
                        spin_unlock_irq(&x->wait.lock);
                        timeout = schedule_timeout(timeout);
                        spin_lock_irq(&x->wait.lock);
-
-                       /*
-                        * If the completion has arrived meanwhile
-                        * then return 1 jiffy time left:
-                        */
-                       if (x->done && !timeout) {
-                               timeout = 1;
-                               break;
-                       }
-
-                       if (!timeout) {
-                               __remove_wait_queue(&x->wait, &wait);
-                               return timeout;
-                       }
-               } while (!x->done);
+               } while (!x->done && timeout);
                __remove_wait_queue(&x->wait, &wait);
+               if (!x->done)
+                       return timeout;
        }
        x->done--;
-       return timeout;
+       return timeout ?: 1;
 }
 
 static long __sched