最終更新:2013-08-16 (金) 07:40:55 (2357d)  

wait_event_interruptible
Top / wait_event_interruptible

sleep until a condition gets true

wait_event_interruptible(wq, condition);

https://www.kernel.org/doc/htmldocs/device-drivers/API-wait-event-interruptible.html

概要

  • The process is put to sleep (TASK_INTERRUPTIBLE) until the condition evaluates to true or a signal is received. The condition is checked each time the waitqueue wq is woken up.
  • wake_up has to be called after changing any variable that could change the result of the wait condition.
  • The function will return -ERESTARTSYS? if it was interrupted by a signal and 0 if condition evaluated to true.

動作

  • condition に指定された式が0である場合は現在のプロセスを待ち状態にする
  • 待ち状態が解除(wake_up)されるとまたconditionの判定を行い、0であれば再度プロセスを 待ち状態にする
  • condition が非 0 あるいはシグナルによって 割り込まれた場合に、待機終了

中身

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