This article has been transferred from Reille blog: http://velep.com/archives/815.html
Waiting queues play a pivotal role in the Linux kernel, and many Linux drivers are more or less involved in waiting queues. Therefore, for the Linux kernel and driver developers, mastering the waiting queue is one of the necessary lessons. The waiting queue of Linux kernel is based on the double cyclic list, which is closely combined with the process scheduling mechanism, and can be used to realize the core asynchronous event notification mechanism. It has two types of data structures: the wait queue header (wait_queue_head_t) and the Wait queue item (wait_queue_t). Both the wait queue header and the Wait queue item contain a list_head type of domain as a "join". It is linked by a doubly linked list and a list of waiting processes, with the headers for the task. The following is a specific description.
First, the definition:
Header file:/include/linux/wait.h
1 |
struct __wait_queue_head { |
3 |
struct List_head task_list; |
5 |
typedef struct __WAIT_QUEUE_HEAD wait_queue_head_t; |
Second, the role:
In the kernel, waiting queues are of great use, especially in interrupt processing, process synchronization, timing, and so on. You can use the wait queue to wake up the blocking process. It is based on the queue as the basic data structure, and the process scheduling mechanism in close combination, can be used to implement the asynchronous event notification mechanism in the kernel, synchronization of access to system resources.
Three, the field detailed:
1, spinlock_t lock;
In the process of task_list and operation, this lock is used to implement mutually exclusive access to the waiting queue.
2, srtuct list_head_t task_list;
Two-way cyclic linked list, storing the waiting process.
Third, the operation:
1. Define and Initialize:
(1)