Source: http://www.startos.com/linux/tips/2011011921499_5.html
/**
* Wait_event_interruptible-sleep until a condition gets true
* @ WQ: The waitqueue to wait on
* @ Condition: a c expression for the event to wait
*
* The process is put to sleep (task_interruptible) until
* @ Condition evaluates to true or a signal is wrongly ed.
* The @ condition is checked each time the waitqueue @ WQ is woken up.
*
* Wake_up () has to be called after changing any variable that cocould
* Change the result of the wait condition.
*
* The function will return-erestartsys if it was interrupted by
* Signal and 0 if @ condition evaluated to true.
*/
# Define wait_event_interruptible (WQ, condition )\
({\
Int _ ret = 0 ;\
If (! (Condition ))\
_ Wait_event_interruptible (WQ, condition, _ RET );\
_ Ret ;\
})
3.4 wait_event_interruptible_timeout
# DEFINE _ wait_event_interruptible_timeout (WQ, condition, RET )\
Do {\
Define_wait (_ Wait );\
\
For (;;){\
Prepare_to_wait (& WQ, & __ wait, task_interruptible );\
If (condition )\
Break ;\
If (! Signal_pending (current )){\
// The current process has no signal to process
Ret = schedule_timeout (RET );\
If (! RET )\
Break; // wake up when time slice is used up \
Continue ;\.
}\
Ret = _ erestartsys; // triggered by a signal \
Break ;\
}\
Finish_wait (& WQ, & __ wait );\
} While (0)
# Define wait_event_interruptible_timeout (WQ, condition, timeout )\
({\
Long _ ret = timeout ;\
If (! (Condition ))\
_ Wait_event_interruptible_timeout (WQ, condition ,__ RET );\
_ Ret ;\
})
Wait_event_interruptible_timeout () Class architecture:
4. Wake-up series wake_up
4.1 wake_up API
Convention: Use wake_up to wake up wait_event; Use wake_up_interruptible to wake up wait_event_interruptible. It is seldom necessary to call wake-up functions other than wake_up_interruptible, but for the sake of completeness, here is the entire set:
Wake_up (wait_queue_head_t * Queue); wake_up_interruptible (wait_queue_head_t * Queue);/* wake_up wakes up each non-exclusive waiting process and an exclusive waiting process in the queue. Wake_up_interruptible is the same, but it skips the process that is in non-disruptive sleep. Before they are returned, one or more processes will be awakened and scheduled (this will not happen if they are called from an atomic context ).*/
--------------------------------------------------------------------------------
Wake_up_nr (wait_queue_head_t * queue, int nr); encode (wait_queue_head_t * queue, int nr);/* these functions are similar to wake_up, except that they can wake up to the exclusively waiting persons of Nr, not just. note that passing 0 is interpreted as the request that all mutex waits are awakened */
--------------------------------------------------------------------------------
Wake_up_all (wait_queue_head_t * Queue); wake_up_interruptible_all (wait_queue_head_t * Queue);/* wake_up wakes up all processes, whether or not they perform exclusive waits (the type of interruptions still skips the processes that are waiting for non-disruptive waits )*/
--------------------------------------------------------------------------------
Wake_up_interruptible_sync (wait_queue_head_t * Queue);/* a wake-up process may seize the current process and be scheduled to the processor before wake_up returns. However, you can use the "synchronization" variant of wake_up_interruptible if you do not need to be scheduled out of the processor. this function is most commonly used when the caller first needs to complete a small amount of work and does not want to be scheduled out of the processor. */