1. Why do I need to use the waiting queue? Waiting queue is a necessity for the drive of blocking character devices. Blocking indicates that a device is readable or writable. However, at some point, the device has nothing to read from you, but your application (process) operations need to read data from the device, there is no way, either an error occurs, or the block is there waiting to read the data. Once the device has something to read to you, the process can continue the read operation.
2. Define and initialize the waiting queue.
(1) Define "waiting queue Header"
Wait_queue_head_t my_queue;
(2) initialize the "waiting queue Header"
Init_waitqueue_head (& my_queue );
Define and initialize shortcuts:
Declare_wait_queue_head (my_queue );
3. Where can I use the waiting queue? In your operation function. For example, read or write operations.
Wait_event (queue, condition );
Wait_event_interruptible (queue, condition );
Wait_event_timeout (queue, condition, timeout );
Wait_event_interruptible_timeout (queue, condition, timeout );
Wait for the first parameter queue to be awakened as the waiting queue header, and the second parameter condition must be met; otherwise, it will be blocked. The difference between wait_event () and wait_event_interruptible () is that the latter can be interrupted by signals, but the former cannot. The macro after timeout indicates the timeout time of the blocking wait. In jiffy, when the timeout of the third parameter arrives, no matter whether the condition is satisfied or not, it is returned.
4. Where to wake up and how to wake up? The wake-up method corresponds to the waiting event.
Void wake_up (wait_queue_head_t * Queue );
Void wake_up_interruptible (wait_queue_head_t * Queue );
The above operation will wake up all processes corresponding to the waiting queue with the queue as the waiting queue header.
Wake_up () <---> wait_event ()
Wait_event_timeout ()
Wake_up_interruptible () <---> wait_event_interruptible ()
Wait_event_interruptible_timeout ()
Wake_up () can wake up processes in task_interruptible and task_uninterruptible.
Wake_up_interruptble () can only wake up processes in task_interruptible.
The wake-up operation is generally executed in the interrupt program. Remember that condition must be assigned true to truly wake up !!
Source: http://markter.blog.163.com/blog/static/173553995201182875330918/