First, Introduction
Ngx_queue_t is a doubly linked list implemented in Nginx, which embeds ngx_queue_t into a custom structure in a custom structure that uses a doubly linked list. Another feature is that ngx_queue_t does not involve memory allocations.
Ii. examples
The following source code is the "Deep Understanding Nginx" 7th chapter on the ngx_queue_t of the source integration. Makefile is the reference http://blog.csdn.net/livelylittlefish/article/details/6586946.
#include
#include "Ngx_config.h"
#include "ngx_conf_file.h"
#include "nginx.h"
#include "ngx_core.h"
#include "Ngx_string.h"
#include "ngx_palloc.h"
#include "ngx_queue.h"
Volatile ngx_cycle_t *ngx_cycle;
void Ngx_log_error_core (ngx_uint_t level,ngx_log_t *log, ngx_err_t err,
const char *FMT, ...)
{
}
typedef struct {
U_CHAR*STR;
Ngx_queue_tqele;
Intnum;
}testnode;
ngx_int_t Comptestnode (const ngx_queue_t*a, const ngx_queue_t *b)
{
Testnode*anode = Ngx_queue_data (A, Testnode, Qele);
Testnode*bnode = Ngx_queue_data (b, Testnode, Qele);
Returnanode->num > bnode->num;
}
int main ()
{
Ngx_queue_tqueuecontainer;
Ngx_queue_init (&queuecontainer);
inti = 0;
TESTNODENODE[5];
for (; i < 5; + + i) {
Node[i].num= i;
}
Ngx_queue_insert_tail (&queuecontainer,&node[0].qele);
Ngx_queue_insert_head (&queuecontainer,&node[1].qele);
Ngx_queue_insert_tail (&queuecontainer,&node[2].qele);
Ngx_queue_insert_after (&queuecontainer,&node[3].qele);
Ngx_queue_insert_tail (&queuecontainer,&node[4].qele);
Ngx_queue_t*q;
for (q = Ngx_queue_head (&queuecontainer);
q!= Ngx_queue_sentinel (&queuecontainer);
q= Ngx_queue_next (q)) {
Testnode*elenode = Ngx_queue_data (q, Testnode, Qele);
printf ("%d\n", elenode->num);
}
printf ("*****sort*****\n");
Ngx_queue_sort (&queuecontainer,comptestnode);
for (q = Ngx_queue_head (&queuecontainer);
q!= Ngx_queue_sentinel (&queuecontainer);
q= Ngx_queue_next (q)) {
Testnode*elenode = Ngx_queue_data (q, Testnode, Qele);
printf ("%d\n", elenode->num);
}
Return0;
}
Makefile
CXX = gcc
Cxxflags + =-g-wall-wextra
Ngx_root =/usr/src/nginx-1.0.4
TARGETS = Test_queue
Targets_c_file = $ (TARGETS). C
CLEANUP = rm-f $ (TARGETS) *.O
All: $ (TARGETS)
Clean
$ (CLEANUP)
Core_incs =-i.\
-i$ (ngx_root)/src/core\
-i$ (ngx_root)/src/event\
-i$ (ngx_root)/src/event/modules\
-i$ (ngx_root)/src/os/unix\
-i$ (ngx_root)/objs\
Ngx_palloc =$ (ngx_root)/OBJS/SRC/CORE/NGX_PALLOC.O
Ngx_string =$ (ngx_root)/OBJS/SRC/CORE/NGX_STRING.O
Ngx_alloc = $ (ngx_root)/OBJS/SRC/OS/UNIX/NGX_ALLOC.O
Ngx_queue =$ (ngx_root)/OBJS/SRC/CORE/NGX_QUEUE.O
$ (TARGETS): $ (targets_c_file)
$ (CXX) $ (cxxflags) $ (core_incs) $ (ngx_palloc) $ (ngx_string) $ (ngx_alloc) $ (ngx_queue) $^-O $@
Iii. Summary
1. A linked list is identified by a linked list header and does not contain user-defined data.
The above describes the Nginx doubly linked list ngx_queue_t, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.