标签(空格分隔): 等待队列
http://bbs.chinaunix.net/thread-3615327-1-1.html
do { DEFINE_WAIT(__wait); for (;;) { // break可以退出 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); if (condition) break; ret = schedule_timeout(ret); if (!ret) /若timeout为等完,则进入下一次循环继续等 / break; //若timeout超时,退出 */ } \ finish_wait(&wq, &__wait);
schedule_timeout有两种情况退出: 1. wake_up; 2. timer超时;
wake_up会把schedule_timeout打断,此时schedule_timeout注册的定时器并未超时,schedule_timeout直接返回,回到for(;循环,这个循环只有break才能推出,而break有两种情况: 1. 条件为真; 2. ret==0,也就是超时;
如果调用wake_up而condition不为真,则再次调用schedule_timeout,不过此时传入的时间,是上次剩余的时间,当其超时时,wait_event_timeout同样会执行到break退出,所以不会无限的执行下去: /** * wait_event_timeout - sleep until a condition gets true or a timeout elapses * @wq: the waitqueue to wait on * @condition: a C expression for the event to wait for * @timeout: timeout, in jiffies * * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the * @condition evaluates to true. 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. *
