Linux wait queues wait_queue_head_t and Wait_queue_t__linux

Source: Internet
Author: User
Tags data structures

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 {
2 spinlock_t lock;
3 struct List_head task_list;
4 };
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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.