我们先写下该函数的含义:先判断一下condition条件,如果条件不成立,则将当前进程挂在等待队列中,如果条件成立,则唤醒等待队列.
在kernel-4.14/include/linux/wait.h中,有着大量的wait_event类的API函数,
wait_event(wq_head, condition)
wait_event_timeout(wq_head, condition, timeout)
wait_event_interruptible(wq_head, condition)
wait_event_interruptible_timeout(wq_head, condition, timeout)
wait_event_freezable(wq_head, condition)
wait_event_freezable_timeout(wq_head, condition, timeout)
wait_event_exclusive_cmd(wq_head, condition, cmd1, cmd2)
wait_event_cmd(wq_head, condition, cmd1, cmd2)
wait_event_hrtimeout(wq_head, condition, timeout)
wait_event_interruptible_hrtimeout(wq, condition, timeout)
wait_event_interruptible_exclusive(wq, condition)
wait_event_killable_exclusive(wq, condition)
wait_event_freezable_exclusive(wq, condition)
wait_event_interruptible_locked(wq, condition)
wait_event_interruptible_locked_irq(wq, condition)
wait_event_interruptible_exclusive_locked(wq, condition)
wait_event_interruptible_exclusive_locked_irq(wq, condition)
wait_event_killable(wq_head, condition)
wait_event_killable_timeout(wq_head, condition, timeout)
wait_event_lock_irq_cmd(wq_head, condition, lock, cmd)
wait_event_lock_irq(wq_head, condition, lock)
wait_event_interruptible_lock_irq_cmd(wq_head, condition, lock, cmd)
wait_event_interruptible_lock_irq(wq_head, condition, lock)
wait_event_interruptible_lock_irq_timeout(wq_head, condition, lock, timeout)
然后我们挑选出一个常用的来介绍:
wait_event(wq_head, condition)
- condition = 0 ///cpu继续休眠,其实就是将cpu schedule()出去,当前进程挂在等待队列中
- condition = 1 ///唤醒工作队列
接着我们对上述的sub name进行介绍:
- _timeout: 如果带了_timeout,那么在检查condition条件时,如果不成立,则会等待timeout时间后,再检查一次.
- _interruptible : 此时cpu已经schedule()出去,这时来个系统级的中断,是可以唤醒这个等待队列的
下面我们选取wait_event_interruptible()和wait_event_interruptible_timeout()来介绍其实现原理: