: 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?
- Typedef struct ngx_queue_s ngx_queue_t;
- Struct ngx_queue_s {
- Ngx_queue_t * prev;
- Ngx_queue_t * next;
- };
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?
- Src/core/ngx_queue.h
- # 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?
- Ngx_queue_t * ngx_queue_middle (ngx_queue_t * queue) // find the queue in the middle
- 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.