sched: refactor wait_for_completion_timeout()

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>

authored by Oleg Nesterov and committed by Ingo Molnar ea71a546 bb10ed09

+6 -18
+6 -18
kernel/sched.c
··· 4398 signal_pending(current)) || 4399 (state == TASK_KILLABLE && 4400 fatal_signal_pending(current))) { 4401 - __remove_wait_queue(&x->wait, &wait); 4402 - return -ERESTARTSYS; 4403 } 4404 __set_current_state(state); 4405 spin_unlock_irq(&x->wait.lock); 4406 timeout = schedule_timeout(timeout); 4407 spin_lock_irq(&x->wait.lock); 4408 - 4409 - /* 4410 - * If the completion has arrived meanwhile 4411 - * then return 1 jiffy time left: 4412 - */ 4413 - if (x->done && !timeout) { 4414 - timeout = 1; 4415 - break; 4416 - } 4417 - 4418 - if (!timeout) { 4419 - __remove_wait_queue(&x->wait, &wait); 4420 - return timeout; 4421 - } 4422 - } while (!x->done); 4423 __remove_wait_queue(&x->wait, &wait); 4424 } 4425 x->done--; 4426 - return timeout; 4427 } 4428 4429 static long __sched
··· 4398 signal_pending(current)) || 4399 (state == TASK_KILLABLE && 4400 fatal_signal_pending(current))) { 4401 + timeout = -ERESTARTSYS; 4402 + break; 4403 } 4404 __set_current_state(state); 4405 spin_unlock_irq(&x->wait.lock); 4406 timeout = schedule_timeout(timeout); 4407 spin_lock_irq(&x->wait.lock); 4408 + } while (!x->done && timeout); 4409 __remove_wait_queue(&x->wait, &wait); 4410 + if (!x->done) 4411 + return timeout; 4412 } 4413 x->done--; 4414 + return timeout ?: 1; 4415 } 4416 4417 static long __sched