Nginx source code learning notes (9) -- Basic container -- queue

Source: Internet
Author: User
: This article mainly introduces the nginx source code study notes (9)-basic container-queue. For more information about PHP tutorials, see. Src/core/ngx_queue. {c | h} implements QueueOperation logic, QueueThe basic structure of is a bidirectional Queue

The basic data structure is:

[Cpp] view plaincopyprint?

  1. Typedef struct ngx_queue_s ngx_queue_t;
  2. Struct ngx_queue_s {
  3. Ngx_queue_t * prev;
  4. Ngx_queue_t * next;
  5. };


According to the data structure, we can find that the nginxQueueOperations and structures only perform pointer operations, and are not responsible for the distribution and storage of node content space. Therefore, when you define your ownQueueWhen creating a node, you need to define the data structure and allocate space, and include a member of the ngx_queue_t type. to obtain the original data node, you need to use the ngx_queue_data macro:

[Cpp] view plaincopyprint?

  1. Src/core/ngx_queue.h
  2. # Define ngx_queue_data (q, type, link) (type *) (u_char *) q-offsetof (type, link ))


In addition, the entire queue structure contains an sentinel node, which pointsQueue.


After reading the source code of queue, we found that there are only two methods to achieve this:

[Cpp] view plaincopyprint?

  1. Ngx_queue_t * ngx_queue_middle (ngx_queue_t * queue) // find the queue in the middle
  2. Void ngx_queue_sort (ngx_queue_t * queue, ngx_int_t (* cmp) (const ngx_queue_t *, const ngx_queue_t *) // seemingly yesInsert sort, // No more


Ngx_queue_init initializationQueue

Ngx_queue_empty clears all nodes before a node.

Ngx_queue_insert_head insert a node after the specified node

Ngx_queue_insert_after insert a node after the specified node
Ngx_queue_insert_tail inserts a node before the specified node
Ngx_queue_head: obtain the next node of the node.
Ngx_queue_next get the next node of the node
Ngx_queue_last get the previous node of the node
Ngx_queue_prev: obtain the previous node of the node.
Ngx_queue_sentinel: obtain the current node.
Ngx_queue_remove deleteQueueA node in
Obtain ngx_queue_data.QueueData of a node
Ngx_queue_split
Ngx_queue_add
Ngx_queue_middle
Ngx_queue_sort

The above introduces the nginx source code learning notes (9) -- Basic container -- queue, including the queue and Insertion sorting content, and hopes to help friends who are interested in the PHP Tutorial.

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.