SIMPLEQ_INSERT_TAIL, SIMPLEQ_INSERT_AFTER, SIMPLEQ_REMOVE_HEAD, SIMPLEQ_REMOVE, SIMPLEQ_FOREACH, SIMPLEQ_EMPTY, SIMPLEQ_FIRST, SIMPLEQ_NEXT, STAILQ_HEAD, STAILQ_HEAD_INITIALIZER, STAILQ_ENTRY, STAILQ_INIT, STAILQ_INSERT_HEAD, STAILQ_INSERT_TAIL, STAILQ_INSERT_AFTER, STAILQ_REMOVE_HEAD, S...
queue, SLIST_HEAD , SLIST_HEAD_INITIALIZER , SLIST_ENTRY , SLIST_INIT , SLIST_INSERT_AFTER , SLIST_INSERT_HEAD , SLIST_REMOVE_HEAD , SLIST_REMOVE , SLIST_FOREACH...
插入元素用TAILQ_INSERT_TAIL宏,由于TAILQ中有一个tqh_last的二级指针,所以插入元素直接插到队尾,仅用O(1)时间。 578 #define TAILQ_INSERT_TAIL(head, elm, field) do { 579 QMD_TAILQ_CHECK_TAIL(head, field); 580 TAILQ_NEXT((elm), field) = NULL; 581 (elm)->field.tqe_prev = (head)->tq...
TAILQ_INSERT_TAIL(&my_tailq_head, item, entries); //遍历队列 printf("Forward traversal: "); TAILQ_FOREACH(item, &my_tailq_head, entries) printf("%d ",item->value); printf("\n"); //添加一个新的元素 printf("Adding new item after 5: "); TAILQ_FOREACH(item, &my_tailq_head, en...
TAILQ_INSERT_TAIL(&queue_head, item, entries); } struct QUEUE_ITEM *ins_item; ins_item=malloc(sizeof(ins_item)); ins_item->value=100; TAILQ_INSERT_BEFORE(item,ins_item,entries); tmp_item=TAILQ_FIRST(&queue_head); printf("first element is %d\n",tmp_item->value); ...
defineCPP_TAILQ_INSERT_TAIL(head,elm,field)do{\CPP_TAILQ_NEXT((elm),field)=NULL;\(elm)->field.tqe_prev=(head)->tqh_last;\*(head)->tqh_last=(elm);\(head)->tqh_last=&CPP_TAILQ_NEXT((elm),field);\}while(0)#defineCPP_TAILQ_CONCAT(head1,head2,field)do{\if(!
我有一个尾部结构: int file; int pos; close(np->file);} TAILQ_INSERT_TAIL(&tailq_head[thread_id], np,
TAILQ_INSERT_TAIL(head, elm, field) ... 这些接口的实现和更多的操作接口可以参考FreeBSD queue TAILQ队列中为什么tqh_prev和tqh_last要使用二级指针 要搞清楚这个问题,我们可以考虑如果不使用二级指针会怎么样? 就像定义成下面这样。 #define FAKE_TAILQ_HEAD(name, type) \ struct...
#defineTAILQ_INSERT_TAIL(head, elm, field) do { \(elm)->field.tqe_next =NULL; \ (elm)->field.tqe_prev = (head)->tqh_last; \*(head)->tqh_last =(elm); \ (head)->tqh_last = &(elm)->field.tqe_next; \ }while(0) ...
TAILQ_INSERT_TAIL(&queue_head, item, entries); } struct QUEUE_ITEM *ins_item; ins_item=malloc(sizeof(ins_item)); ins_item->value=100; TAILQ_INSERT_BEFORE(item,ins_item,entries); tmp_item=TAILQ_FIRST(&queue_head); printf("first element is %d\n",tmp_item->value); ...