Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../.././../../../usr/man/man9f/queue.9f
Real path: /usr/share/man/man9f/queue.9f
Zurück
'\" te .\" Copyright (c) 1991, 1993, Regents of the University of California. All rights reserved. The Berkeley software License Agreement specifies the terms and conditions for redistribution. .\" Portions Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. .\" Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .TH queue 9F "14 May 2018" "Oracle Solaris 11.4" "Kernel Functions" .SH NAME queue, SLIST_HEAD, SLIST_HEAD_INITIALIZER, SLIST_ENTRY, SLIST_INIT, SLIST_INSERT_AFTER, SLIST_INSERT_HEAD, SLIST_REMOVE_HEAD, SLIST_REMOVE, SLIST_FOREACH, SLIST_EMPTY, SLIST_FIRST, SLIST_NEXT, SIMPLEQ_HEAD, SIMPLEQ_HEAD_INITIALIZER, SIMPLEQ_ENTRY, SIMPLEQ_INIT, SIMPLEQ_INSERT_HEAD, 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, STAILQ_REMOVE, STAILQ_FOREACH, STAILQ_EMPTY, STAILQ_FIRST, STAILQ_NEXT, STAILQ_CONCAT, LIST_HEAD, LIST_HEAD_INITIALIZER, LIST_ENTRY, LIST_INIT, LIST_INSERT_AFTER, LIST_INSERT_BEFORE, LIST_INSERT_HEAD, LIST_REMOVE, LIST_FOREACH, LIST_EMPTY, LIST_FIRST, LIST_NEXT, TAILQ_HEAD, TAILQ_HEAD_INITIALIZER, TAILQ_ENTRY, TAILQ_INIT, TAILQ_INSERT_HEAD, TAILQ_INSERT_TAIL, TAILQ_INSERT_AFTER, TAILQ_INSERT_BEFORE, TAILQ_REMOVE, TAILQ_FOREACH, TAILQ_FOREACH_REVERSE, TAILQ_EMPTY, TAILQ_FIRST, TAILQ_NEXT, TAILQ_LAST, TAILQ_PREV, TAILQ_CONCAT, CIRCLEQ_HEAD, CIRCLEQ_HEAD_INITIALIZER, CIRCLEQ_ENTRY, CIRCLEQ_INIT, CIRCLEQ_INSERT_AFTER, CIRCLEQ_INSERT_BEFORE, CIRCLEQ_INSERT_HEAD, CIRCLEQ_INSERT_TAIL, CIRCLEQ_REMOVE, CIRCLEQ_FOREACH, CIRCLEQ_FOREACH_REVERSE, CIRCLEQ_EMPTY, CIRCLEQ_FIRST, CIRCLEQ_LAST, CIRCLEQ_NEXT, CIRCLEQ_PREV, CIRCLEQ_LOOP_NEXT, CIRCLEQ_LOOP_PREV \- implementations of singly-linked lists, simple queues, lists, tail queues, and circular queues .SH SYNOPSIS .LP .nf #include <sys/queue.h> SLIST_HEAD(\fIHEADNAME\fR, \fITYPE\fR); .fi .LP .nf SLIST_HEAD_INITIALIZER(\fIhead\fR); .fi .LP .nf SLIST_ENTRY(\fITYPE\fR); .fi .LP .nf SLIST_INIT(SLIST_HEAD *\fIhead\fR) .fi .LP .nf SLIST_INSERT_AFTER(TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, SLIST_ENTRY \fINAME\fR); .fi .LP .nf SLIST_INSERT_HEAD(SLIST_HEAD *\fIhead\fR, TYPE *\fIelm\fR, SLIST_ENTRY \fINAME\fR) .fi .LP .nf SLIST_REMOVE_HEAD(SLIST_HEAD *\fIhead\fR, SLIST_ENTRY \fINAME\fR); .fi .LP .nf SLIST_REMOVE(SLIST_HEAD *\fIhead\fR, TYPE *\fIelm\fR, \fITYPE\fR, SLIST_ENTRY \fINAME\fR); .fi .LP .nf SLIST_FOREACH(TYPE *\fIvar\fR, SLIST_HEAD *\fIhead\fR, SLIST_ENTRY \fINAME\fR); .fi .LP .nf int SLIST_EMPTY(SLIST_HEAD *\fIhead\fR); .fi .LP .nf TYPE *SLIST_FIRST(SLIST_HEAD *\fIhead\fR); .fi .LP .nf TYPE *SLIST_NEXT(TYPE *\fIelm\fR, SLIST_ENTRY \fINAME\fR); .fi .LP .nf SIMPLEQ_HEAD(\fIHEADNAME\fR, \fITYPE\fR); .fi .LP .nf SIMPLEQ_HEAD_INITIALIZER(\fIhead\fR); .fi .LP .nf SIMPLEQ_ENTRY(\fITYPE\fR); .fi .LP .nf SIMPLEQ_INIT(SIMPLEQ_HEAD *\fIhead\fR); .fi .LP .nf SIMPLEQ_INSERT_HEAD(SIMPLEQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, SIMPLEQ_ENTRY \fINAME\fR); .fi .LP .nf SIMPLEQ_INSERT_TAIL(SIMPLEQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, SIMPLEQ_ENTRY \fINAME\fR); .fi .LP .nf SIMPLEQ_INSERT_AFTER(SIMPLEQ_HEAD *\fIhead\fR, TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, SIMPLEQ_ENTRY \fINAME\fR); .fi .LP .nf SIMPLEQ_REMOVE_HEAD(SIMPLEQ_HEAD *\fIhead\fR, SIMPLEQ_ENTRY \fINAME\fR); .fi .LP .nf SIMPLEQ_REMOVE(SIMPLEQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, \fITYPE\fR, SIMPLEQ_ENTRY \fINAME\fR); .fi .LP .nf SIMPLEQ_FOREACH(TYPE *\fIvar\fR, SIMPLEQ_HEAD *\fIhead\fR, SIMPLEQ_ENTRY \fINAME\fR); .fi .LP .nf int SIMPLEQ_EMPTY(SIMPLEQ_HEAD *\fIhead\fR) .fi .LP .nf TYPE *SIMPLEQ_FIRST(SIMPLEQ_HEAD *\fIhead\fR); .fi .LP .nf TYPE *SIMPLEQ_NEXT(TYPE *\fIelm\fR, SIMPLEQ_ENTRY \fINAME\fR); .fi .LP .nf STAILQ_HEAD(\fIHEADNAME\fR, \fITYPE\fR); .fi .LP .nf STAILQ_HEAD_INITIALIZER(\fIhead\fR); .fi .LP .nf STAILQ_ENTRY(\fITYPE\fR); .fi .LP .nf STAILQ_INIT(STAILQ_HEAD *\fIhead\fR); .fi .LP .nf STAILQ_INSERT_HEAD(STAILQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, STAILQ_ENTRY \fINAME\fR); .fi .LP .nf STAILQ_INSERT_TAIL(STAILQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, STAILQ_ENTRY \fINAME\fR); .fi .LP .nf STAILQ_INSERT_AFTER(STAILQ_HEAD *\fIhead\fR, TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, STAILQ_ENTRY \fINAME\fR); .fi .LP .nf STAILQ_REMOVE_HEAD(STAILQ_HEAD *\fIhead\fR, STAILQ_ENTRY \fINAME\fR); .fi .LP .nf STAILQ_REMOVE(STAILQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, \fITYPE\fR, STAILQ_ENTRY \fINAME\fR); .fi .LP .nf STAILQ_FOREACH(TYPE *\fIvar\fR, STAILQ_HEAD *\fIhead\fR, STAILQ_ENTRY \fINAME\fR); .fi .LP .nf int STAILQ_EMPTY(STAILQ_HEAD *\fIhead\fR); .fi .LP .nf TYPE *STAILQ_FIRST(STAILQ_HEAD *\fIhead\fR); .fi .LP .nf TYPE *STAILQ_NEXT(TYPE *\fIelm\fR, STAILQ_ENTRY \fINAME\fR); .fi .LP .nf STAILQ_CONCAT(STAILQ_HEAD *\fIhead1\fR, STAILQ_HEAD *\fIhead2\fR); .fi .LP .nf LIST_HEAD(\fIHEADNAME\fR, \fITYPE\fR); .fi .LP .nf LIST_HEAD_INITIALIZER(\fIhead\fR); .fi .LP .nf LIST_ENTRY(\fITYPE\fR); .fi .LP .nf LIST_INIT(LIST_HEAD *\fIhead\fR); .fi .LP .nf LIST_INSERT_AFTER(TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, LIST_ENTRY \fINAME\fR); .fi .LP .nf LIST_INSERT_BEFORE(TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, LIST_ENTRY \fINAME\fR); .fi .LP .nf LIST_INSERT_HEAD(LIST_HEAD *\fIhead\fR, TYPE *\fIelm\fR, LIST_ENTRY \fINAME\fR); .fi .LP .nf LIST_REMOVE(TYPE *\fIelm\fR, LIST_ENTRY \fINAME\fR); .fi .LP .nf LIST_FOREACH(TYPE *\fIvar\fR, LIST_HEAD *\fIhead\fR, LIST_ENTRY \fINAME\fR); .fi .LP .nf int LIST_EMPTY(LIST_HEAD *\fIhead\fR); .fi .LP .nf TYPE *LIST_FIRST(LIST_HEAD *\fIhead\fR); .fi .LP .nf TYPE *LIST_NEXT(TYPE *\fIelm\fR, LIST_ENTRY \fINAME\fR); .fi .LP .nf TAILQ_HEAD(\fIHEADNAME\fR, \fITYPE\fR); .fi .LP .nf TAILQ_HEAD_INITIALIZER(\fIhead\fR); .fi .LP .nf TAILQ_ENTRY(\fITYPE\fR); .fi .LP .nf TAILQ_INIT(TAILQ_HEAD *\fIhead\fR); .fi .LP .nf TAILQ_INSERT_HEAD(TAILQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf TAILQ_INSERT_TAIL(TAILQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, TAILQ_ENTRY \fINAME\fR) .fi .LP .nf TAILQ_INSERT_AFTER(TAILQ_HEAD *\fIhead\fR, TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf TAILQ_INSERT_BEFORE(TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf TAILQ_REMOVE(TAILQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf TAILQ_FOREACH(TYPE *\fIvar\fR, TAILQ_HEAD *\fIhead\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf TAILQ_FOREACH_REVERSE(TYPE *\fIvar\fR, TAILQ_HEAD *\fIhead\fR, \fIHEADNAME\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf int TAILQ_EMPTY(TAILQ_HEAD *\fIhead\fR); .fi .LP .nf TYPE *TAILQ_FIRST(TAILQ_HEAD *\fIhead\fR); .fi .LP .nf TYPE *TAILQ_NEXT(TYPE *\fIelm\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf TYPE *TAILQ_LAST(TAILQ_HEAD *\fIhead\fR, \fIHEADNAME\fR); .fi .LP .nf TYPE *TAILQ_PREV(TYPE *\fIelm\fR, \fIHEADNAME\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf TAILQ_CONCAT(TAILQ_HEAD *\fIhead1\fR, TAILQ_HEAD *\fIhead2\fR, TAILQ_ENTRY \fINAME\fR); .fi .LP .nf CIRCLEQ_HEAD(\fIHEADNAME\fR, \fITYPE\fR); .fi .LP .nf CIRCLEQ_HEAD_INITIALIZER(\fIhead\fR); .fi .LP .nf CIRCLEQ_ENTRY(\fITYPE\fR); .fi .LP .nf CIRCLEQ_INIT(CIRCLEQ_HEAD *\fIhead\fR); .fi .LP .nf CIRCLEQ_INSERT_AFTER(CIRCLEQ_HEAD *\fIhead\fR, TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf CIRCLEQ_INSERT_BEFORE(CIRCLEQ_HEAD *\fIhead\fR, TYPE *\fIlistelm\fR, TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf CIRCLEQ_INSERT_HEAD(CIRCLEQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf CIRCLEQ_INSERT_TAIL(CIRCLEQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf CIRCLEQ_REMOVE(CIRCLEQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf CIRCLEQ_FOREACH(TYPE *\fIvar\fR, CIRCLEQ_HEAD *\fIhead\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf CIRCLEQ_FOREACH_REVERSE(TYPE *\fIvar\fR, CIRCLEQ_HEAD *\fIhead\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf int CIRCLEQ_EMPTY(CIRCLEQ_HEAD *\fIhead\fR); .fi .LP .nf TYPE *CIRCLEQ_FIRST(CIRCLEQ_HEAD *\fIhead\fR); .fi .LP .nf TYPE *CIRCLEQ_LAST(CIRCLEQ_HEAD *\fIhead\fR); .fi .LP .nf TYPE *CIRCLEQ_NEXT(TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf TYPE *CIRCLEQ_PREV(TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf TYPE *CIRCLEQ_LOOP_NEXT(CIRCLEQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .LP .nf TYPE *CIRCLEQ_LOOP_PREV(CIRCLEQ_HEAD *\fIhead\fR, TYPE *\fIelm\fR, CIRCLEQ_ENTRY \fINAME\fR); .fi .SH INTERFACE LEVEL .sp .LP Architecture independent level 11 (DDI/DKI). .SH DESCRIPTION .sp .LP These macros define and operate on five types of data structures: singly- linked lists, simple queues, lists, tail queues, and circular queues. All five structures support the following functionality: .RS +4 .TP 1. Insertion of a new entry at the head of the list. .RE .RS +4 .TP 2. Insertion of a new entry before or after any element in the list. .RE .RS +4 .TP 3. Removal of any entry in the list. .RE .RS +4 .TP 4. Forward traversal through the list. .RE .sp .LP Singly-linked lists are the simplest of the five data structures and support only the above functionality. Singly-linked lists are ideal for applications with large datasets and few or no removals, or for implementing a LIFO queue. .RS +4 .TP 1. Entries can be added at the end of a list. .RE .RS +4 .TP 2. They may be concatenated. .RE .sp .LP However: .RS +4 .TP 1. Entries may not be added before any element in the list. .RE .RS +4 .TP 2. All list insertions and removals must specify the head of the list. .RE .RS +4 .TP 3. Each head entry requires two pointers rather than one. .RE .sp .LP Simple queues are ideal for applications with large datasets and few or no removals, or for implementing a FIFO queue. .sp .LP All doubly linked types of data structures (lists, tail queues, and circle queues) additionally allow: .RS +4 .TP 1. Insertion of a new entry before any element in the list. .RE .RS +4 .TP 2. O(1) removal of any entry in the list. .RE .sp .LP However: .RS +4 .TP 1. Each element requires two pointers rather than one. .RE .RS +4 .TP 2. Code size and execution time of operations (except for removal) is about twice that of the singly-linked data structures .RE .sp .LP Linked lists are the simplest of the doubly linked data structures and support only the above functionality over singly-linked lists. .sp .LP Tail queues add the following functionality: .RS +4 .TP 1. Entries can be added at the end of a list. .RE .RS +4 .TP 2. They may be concatenated. .RE .sp .LP However: .RS +4 .TP 1. All list insertions and removals, except insertion before another element, must specify the head of the list. .RE .RS +4 .TP 2. Each head entry requires two pointers rather than one. .RE .RS +4 .TP 3. Code size is about 15% greater and operations run about 20% slower than lists. .RE .sp .LP Circular queues add the following functionality: .RS +4 .TP 1. Entries can be added at the end of a list. .RE .RS +4 .TP 2. They may be traversed backwards, from tail to head. .RE .sp .LP However: .RS +4 .TP 1. All list insertions and removals must specify the head of the list. .RE .RS +4 .TP 2. Each head entry requires two pointers rather than one. .RE .RS +4 .TP 3. The termination condition for traversal is more complex. .RE .RS +4 .TP 4. Code size is about 40% greater and operations run about 45% slower than lists. .RE .sp .LP In the macro definitions, TYPE is the name of a user defined structure, that must contain a field of type \fBLIST_ENTRY\fR, \fBSIMPLEQ_ENTRY\fR, \fBSLIST_ENTRY\fR, \fBTAILQ_ENTRY\fR, or \fBCIRCLEQ_ENTRY\fR, named \fINAME\fR. The argument \fIHEADNAME\fR is the name of a user defined structure that must be declared using the macros \fBLIST_HEAD()\fR, \fBSIMPLEQ_HEAD()\fR, \fBSLIST_HEAD()\fR, \fBTAILQ_HEAD()\fR, or \fBCIRCLEQ_HEAD()\fR. See the examples below for further explanation of how these macros are used. .SS "Summary of Operations" .sp .LP The following table summarizes the supported macros for each type of data structure. .sp .in +2 .nf +-----------------+-------+------+---------+--------+-------+---------+ | | SLIST | LIST | SIMPLEQ | STAILQ | TAILQ | CIRCLEQ | +-----------------+-------+------+---------+--------+-------+---------+ |_EMPTY | + | + | + | + | + | + | |_FIRST | + | + | + | + | + | + | |_FOREACH | + | + | + | + | + | + | |_FOREACH_REVERSE | - | - | - | - | + | + | |_INSERT_AFTER | + | + | + | + | + | + | |_INSERT_BEFORE | - | + | - | - | + | + | |_INSERT_HEAD | + | + | + | + | + | + | |_INSERT_TAIL | - | - | + | + | + | + | |_LAST | - | - | - | - | + | + | |_LOOP_NEXT | - | - | - | - | - | + | |_LOOP_PREV | - | - | - | - | - | + | |_NEXT | + | + | + | + | + | + | |_PREV | - | - | - | - | + | + | |_REMOVE | + | + | + | + | + | + | |_REMOVE_HEAD | + | - | + | + | - | - | |_CONCAT | - | - | - | + | + | - | +-----------------+-------+------+---------+--------+-------+---------+ .fi .in -2 .sp .SH SINGLY-LINKED LISTS .sp .LP A singly-linked list is headed by a structure defined by the \fBSLIST_HEAD()\fR macro. This structure contains a single pointer to the first element on the list. The elements are singly linked for minimum space and pointer manipulation overhead at the expense of O(n) removal for arbitrary elements. New elements can be added to the list after an existing element or at the head of the list. An \fBSLIST_HEAD\fR structure is declared as follows: .sp .in +2 .nf SLIST_HEAD(\fIHEADNAME\fR, \fITYPE\fR) \fIhead\fR; .fi .in -2 .sp .sp .LP where \fIHEADNAME\fR is the name of the structure to be defined, and \fITYPE\fR is the type of the elements to be linked into the list. A pointer to the head of the list can later be declared as: .sp .in +2 .nf struct \fIHEADNAME\fR *\fIheadp\fR; .fi .in -2 .sp .sp .LP The names \fIhead\fR and \fIheadp\fR are user selectable. .sp .LP The macro \fBSLIST_HEAD_INITIALIZER()\fR evaluates to an initializer for the list head .sp .LP The macro \fBSLIST_EMPTY()\fR evaluates to true if there are no elements in the list. .sp .LP The macro \fBSLIST_ENTRY()\fR declares a structure that connects the elements in the list. .sp .LP The macro \fBSLIST_FIRST()\fR returns the first element in the list or \fINULL\fR if the list is empty. .sp .LP The macro \fBSLIST_FOREACH()\fR traverses the list referenced by head in the forward direction, assigning each element in turn to \fIvar\fR. .sp .LP The macro \fBSLIST_INIT()\fR initializes the list referenced by \fIhead\fR. .sp .LP The macro \fBSLIST_INSERT_HEAD()\fR inserts the new element \fIelm\fR at the head of the list. .sp .LP The macro \fBSLIST_INSERT_AFTER()\fR inserts the new element \fIelm\fR after the element \fIlistelm\fR. .sp .LP The macro \fBSLIST_NEXT()\fR returns the next element in the list. .sp .LP The macro \fBSLIST_REMOVE()\fR removes the element \fIelm\fR from the list. .sp .LP The macro \fBSLIST_REMOVE_HEAD()\fR removes the first element from the head of the list. For optimum efficiency, elements being removed from the head of the list should explicitly use this macro instead of the generic \fBSLIST_REMOVE()\fR macro. .SS "Singly-linked List Example" .sp .in +2 .nf SLIST_HEAD(slisthead, entry) head = SLIST_HEAD_INITIALIZER(head); struct slisthead *headp; /* Singly-linked List head. */ struct entry { ... SLIST_ENTRY(entry) entries; /* Singly-linked List. */ ... } *n1, *n2, *n3, *np; SLIST_INIT(&head); /* Initialize the list. */ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ SLIST_INSERT_HEAD(&head, n1, entries); n2 = malloc(sizeof(struct entry)); /* Insert after. */ SLIST_INSERT_AFTER(n1, n2, entries); SLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */ free(n2); n3 = SLIST_FIRST(&head); SLIST_REMOVE_HEAD(&head, entries); /* Deletion from the head. */ free(n3); /* Forward traversal. */ SLIST_FOREACH(np, &head, entries) np-> ... while (!SLIST_EMPTY(&head)) { /* List Deletion. */ n1 = SLIST_FIRST(&head); SLIST_REMOVE_HEAD(&head, entries); free(n1); } .fi .in -2 .sp .SH SIMPLE QUEUES .sp .LP A simple queue is headed by a structure defined by the \fBSIMPLEQ_HEAD()\fR macro. This structure contains a pair of pointers, one to the first element in the simple queue and the other to the last element in the simple queue. The elements are singly linked for minimum space and pointer manipulation overhead at the expense of O(n) removal for arbitrary elements. New elements can be added to the queue after an existing element, at the head of the queue, or at the end of the queue. A \fBSIMPLEQ_HEAD\fR structure is declared as follows: .sp .in +2 .nf SIMPLEQ_HEAD(\fIHEADNAME\fR, \fITYPE\fR) \fIhead\fR; .fi .in -2 .sp .sp .LP where \fIHEADNAME\fR is the name of the structure to be defined, and \fITYPE\fR is the type of the elements to be linked into the simple queue. A pointer to the head of the simple queue can later be declared as: .sp .in +2 .nf struct HEADNAME *\fIheadp\fR; .fi .in -2 .sp .sp .LP The names \fIhead\fR and \fIheadp\fR are user selectable. .sp .LP The macro \fBSIMPLEQ_ENTRY()\fR declares a structure that connects the elements in the simple queue. .sp .LP The macro \fBSIMPLEQ_HEAD_INITIALIZER()\fR provides a value which can be used to initialize a simple queue head at compile time, and is used at the point that the simple queue head variable is declared, like: .sp .in +2 .nf struct \fIHEADNAME\fR \fIhead\fR = SIMPLEQ_HEAD_INITIALIZER(\fIhead\fR); .fi .in -2 .sp .sp .LP The macro \fBSIMPLEQ_INIT()\fR initializes the simple queue referenced by \fIhead\fR. .sp .LP The macro \fBSIMPLEQ_INSERT_HEAD()\fR inserts the new element elm at the head of the simple queue. .sp .LP The macro \fBSIMPLEQ_INSERT_TAIL()\fR inserts the new element elm at the end of the simple queue. .sp .LP The macro \fBSIMPLEQ_INSERT_AFTER()\fR inserts the new element \fIelm\fR after the element \fIlistelm\fR. .sp .LP The macro \fBSIMPLEQ_REMOVE()\fR removes \fIelm\fR from the simple queue. .sp .LP The macro \fBSIMPLEQ_REMOVE_HEAD()\fR removes the first element from the head of the simple queue. For optimum efficiency, elements being removed from the head of the queue should explicitly use this macro instead of the generic \fBSIMPLQ_REMOVE()\fR macro. .sp .LP The macro \fBSIMPLEQ_EMPTY()\fR return true if the simple queue head has no elements. .sp .LP The macro \fBSIMPLEQ_FIRST()\fR returns the first element of the simple queue head. .sp .LP The macro \fBSIMPLEQ_FOREACH()\fR traverses the tail queue referenced by head in the forward direction, assigning each element in turn to \fIvar\fR. .sp .LP The macro \fBSIMPLEQ_NEXT()\fR returns the element after the element \fIelm\fR. .sp .LP The macros prefixed with "\fBSTAILQ_\fR" (\fBSTAILQ_HEAD()\fR, \fBSTAILQ_HEAD_INITIALIZER()\fR, \fBSTAILQ_ENTRY()\fR, \fBSTAILQ_INIT()\fR, \fBSTAILQ_INSERT_HEAD()\fR, \fBSTAILQ_INSERT_TAIL()\fR, \fBSTAILQ_INSERT_AFTER()\fR, \fBSTAILQ_REMOVE_HEAD()\fR, \fBSTAILQ_REMOVE()\fR, \fBSTAILQ_FOREACH()\fR, \fBSTAILQ_EMPTY()\fR, \fBSTAILQ_FIRST()\fR, and \fBSTAILQ_NEXT()\fR) are functionally identical to these simple queue functions, and are provided for compatibility with FreeBSD. .SS "Simple Queue Example" .sp .in +2 .nf SIMPLEQ_HEAD(simplehead, entry) head; struct simplehead *headp; /* Simple queue head. */ struct entry { ... SIMPLEQ_ENTRY(entry) entries; /* Simple queue. */ ... } *n1, *n2, *np; SIMPLEQ_INIT(&head); /* Initialize the queue. */ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ SIMPLEQ_INSERT_HEAD(&head, n1, entries); n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ SIMPLEQ_INSERT_TAIL(&head, n1, entries); n2 = malloc(sizeof(struct entry)); /* Insert after. */ SIMPLEQ_INSERT_AFTER(&head, n1, n2, entries); /* Forward traversal. */ SIMPLEQ_FOREACH(np, &head, entries) np-> ... /* Delete. */ while (SIMPLEQ_FIRST(&head) != NULL) SIMPLEQ_REMOVE_HEAD(&head, entries); if (SIMPLEQ_EMPTY(&head)) /* Test for emptiness. */ printf("nothing to do\en"); .fi .in -2 .sp .SH LISTS .sp .LP A list is headed by a structure defined by the \fBLIST_HEAD()\fR macro. This structure contains a single pointer to the first element on the list. The elements are doubly linked so that an arbitrary element can be removed without traversing the list. New elements can be added to the list after an existing element, before an existing element, or at the head of the list. A \fBLIST_HEAD\fR structure is declared as follows: .sp .in +2 .nf LIST_HEAD(\fIHEADNAME\fR, \fITYPE\fR) \fIhead\fR; .fi .in -2 .sp .sp .LP where \fIHEADNAME\fR is the name of the structure to be defined, and \fITYPE\fR is the type of the elements to be linked into the list. A pointer to the head of the list can later be declared as: .sp .in +2 .nf struct \fIHEADNAME\fR *\fIheadp\fR; .fi .in -2 .sp .sp .LP The names \fIhead\fR and \fIheadp\fR are user selectable. .sp .LP The macro \fBLIST_ENTRY()\fR declares a structure that connects the elements in the list. .sp .LP The macro \fBLIST_HEAD_INITIALIZER()\fR provides a value which can be used to initialize a list head at compile time, and is used at the point that the list head variable is declared, like: .sp .in +2 .nf struct \fIHEADNAME\fR \fIhead\fR = LIST_HEAD_INITIALIZER(\fIhead\fR); .fi .in -2 .sp .sp .LP The macro \fBLIST_INIT()\fR initializes the list referenced by \fIhead\fR. .sp .LP The macro \fBLIST_INSERT_HEAD()\fR inserts the new element \fIelm\fR at the head of the list. .sp .LP The macro \fBLIST_INSERT_AFTER()\fR inserts the new element \fIelm\fR after the element \fIlistelm\fR. .sp .LP The macro \fBLIST_INSERT_BEFORE()\fR inserts the new element \fIelm\fR before the element \fIlistelm\fR. .sp .LP The macro \fBLIST_REMOVE()\fR removes the element \fIelm\fR from the list. .sp .LP The macro \fBLIST_EMPTY()\fR returns \fBtrue\fR if the list head has no elements. .sp .LP The macro \fBLIST_FIRST()\fR returns the first element of the list head. .sp .LP The macro \fBLIST_FOREACH()\fR traverses the list referenced by \fIhead\fR in the forward direction, assigning each element in turn to \fIvar\fR. .sp .LP The macro \fBLIST_NEXT()\fR returns the element after the element \fIelm\fR. .SS "List Example" .sp .in +2 .nf LIST_HEAD(listhead, entry) head; struct listhead *headp; /* List head. */ struct entry { ... LIST_ENTRY(entry) entries; /* List. */ ... } *n1, *n2, *np; LIST_INIT(&head); /* Initialize the list. */ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ LIST_INSERT_HEAD(&head, n1, entries); n2 = malloc(sizeof(struct entry)); /* Insert after. */ LIST_INSERT_AFTER(n1, n2, entries); n2 = malloc(sizeof(struct entry)); /* Insert before. */ LIST_INSERT_BEFORE(n1, n2, entries); /* Forward traversal. */ LIST_FOREACH(np, &head, entries) np-> ... /* Delete. */ while (LIST_FIRST(&head) != NULL) LIST_REMOVE(LIST_FIRST(&head), entries); if (LIST_EMPTY(&head)) /* Test for emptiness. */ printf("nothing to do\en"); .fi .in -2 .sp .SH TAIL QUEUES .sp .LP A tail queue is headed by a structure defined by the \fBTAILQ_HEAD()\fR macro. This structure contains a pair of pointers, one to the first element in the tail queue and the other to the last element in the tail queue. The elements are doubly linked so that an arbitrary element can be removed without traversing the tail queue. New elements can be added to the queue after an existing element, before an existing element, at the head of the queue, or at the end the queue. A \fBTAILQ_HEAD\fR structure is declared as follows: .sp .in +2 .nf TAILQ_HEAD(\fIHEADNAME\fR, \fITYPE\fR) \fIhead\fR; .fi .in -2 .sp .sp .LP where \fIHEADNAME\fR is the name of the structure to be defined, and \fITYPE\fR is the type of the elements to be linked into the tail queue. A pointer to the head of the tail queue can later be declared as: .sp .in +2 .nf struct HEADNAME *headp; .fi .in -2 .sp .sp .LP The names \fIhead\fR and \fIheadp\fR are user selectable. .sp .LP The macro \fBTAILQ_ENTRY()\fR declares a structure that connects the elements in the tail queue. .sp .LP The macro \fBTAILQ_HEAD_INITIALIZER()\fR provides a value which can be used to initialize a tail queue head at compile time, and is used at the point that the tail queue head variable is declared, like: .sp .in +2 .nf struct \fIHEADNAME\fR \fIhead\fR = TAILQ_HEAD_INITIALIZER(\fIhead\fR); .fi .in -2 .sp .sp .LP The macro \fBTAILQ_INIT()\fR initializes the tail queue referenced by \fIhead\fR. .sp .LP The macro \fBTAILQ_INSERT_HEAD()\fR inserts the new element \fIelm\fR at the head of the tail queue. .sp .LP The macro \fBTAILQ_INSERT_TAIL()\fR inserts the new element \fIelm\fR at the end of the tail queue. .sp .LP The macro \fBTAILQ_INSERT_AFTER()\fR inserts the new element \fIelm\fR after the element \fIlistelm\fR. .sp .LP The macro \fBTAILQ_INSERT_BEFORE()\fR inserts the new element \fIelm\fR before the element \fIlistelm\fR. .sp .LP The macro \fBTAILQ_REMOVE()\fR removes the element \fIelm\fR from the tail queue. .sp .LP The macro \fBTAILQ_EMPTY()\fR return true if the tail queue head has no elements. .sp .LP The macro \fBTAILQ_FIRST()\fR returns the first element of the tail queue head. .sp .LP The macro \fBTAILQ_FOREACH()\fR traverses the tail queue referenced by \fIhead\fR in the forward direction, assigning each element in turn to \fIvar\fR. .sp .LP The macro \fBTAILQ_FOREACH_REVERSE()\fR traverses the tail queue referenced by \fIhead\fR in the reverse direction, assigning each element in turn to \fIvar\fR. .sp .LP The macro \fBTAILQ_NEXT()\fR returns the element after the element \fIelm\fR. .sp .LP The macro \fBTAILQ_CONCAT()\fR concatenates the tail queue headed by \fIhead2\fR onto the end of the one headed by \fIhead1\fR removing all entries from the former. .SS "Tail Queue Example" .sp .in +2 .nf TAILQ_HEAD(tailhead, entry) head; struct tailhead *headp; /* Tail queue head. */ struct entry { ... TAILQ_ENTRY(entry) entries; /* Tail queue. */ ... } *n1, *n2, *np; TAILQ_INIT(&head); /* Initialize the queue. */ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ TAILQ_INSERT_HEAD(&head, n1, entries); n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ TAILQ_INSERT_TAIL(&head, n1, entries); n2 = malloc(sizeof(struct entry)); /* Insert after. */ TAILQ_INSERT_AFTER(&head, n1, n2, entries); n2 = malloc(sizeof(struct entry)); /* Insert before. */ TAILQ_INSERT_BEFORE(n1, n2, entries); /* Forward traversal. */ TAILQ_FOREACH(np, &head, entries) np-> ... /* Reverse traversal. */ TAILQ_FOREACH_REVERSE(np, &head, tailhead, entries) np-> ... /* Delete. */ while (TAILQ_FIRST(&head) != NULL) TAILQ_REMOVE(&head, TAILQ_FIRST(&head), entries); if (TAILQ_EMPTY(&head)) /* Test for emptiness. */ printf("nothing to do\en"); .fi .in -2 .sp .SH CIRCULAR QUEUES .sp .LP A circular queue is headed by a structure defined by the \fBCIRCLEQ_HEAD()\fR macro. This structure contains a pair of pointers, one to the first element in the circular queue and the other to the last element in the circular queue. The elements are doubly linked so that an arbitrary element can be removed without traversing the queue. New elements can be added to the queue after an existing element, before an existing element, at the head of the queue, or at the end of the queue. A \fBCIRCLEQ_HEAD\fR structure is declared as follows: .sp .in +2 .nf CIRCLEQ_HEAD(\fIHEADNAME\fR, \fITYPE\fR) \fIhead\fR; .fi .in -2 .sp .sp .LP where \fIHEADNAME\fR is the name of the structure to be defined, and \fITYPE\fR is the type of the elements to be linked into the circular queue. A pointer to the head of the circular queue can later be declared as: .sp .in +2 .nf struct \fIHEADNAME\fR *\fIheadp\fR; .fi .in -2 .sp .sp .LP The names \fIhead\fR and \fIheadp\fR are user selectable. .sp .LP The macro \fBCIRCLEQ_ENTRY()\fR declares a structure that connects the elements in the circular queue. .sp .LP The macro \fBCIRCLEQ_HEAD_INITIALIZER()\fR provides a value which can be used to initialize a circular queue head at compile time, and is used at the point that the circular queue head variable is declared, like: .sp .in +2 .nf struct \fBHEADNAME()\fR \fBhead()\fR = CIRCLEQ_HEAD_INITIALIZER(\fBhead()\fR); .fi .in -2 .sp .sp .LP The macro \fBCIRCLEQ_INIT()\fR initializes the circular queue referenced by \fIhead\fR. .sp .LP The macro \fBCIRCLEQ_INSERT_HEAD()\fR inserts the new element \fIelm\fR at the head of the circular queue. .sp .LP The macro \fBCIRCLEQ_INSERT_TAIL()\fR inserts the new element \fIelm\fR at the end of the circular queue. .sp .LP The macro \fBCIRCLEQ_INSERT_AFTER()\fR inserts the new element \fIelm\fR after the element \fIlistelm\fR. .sp .LP The macro \fBCIRCLEQ_INSERT_BEFORE()\fR inserts the new element \fIelm\fR before the element \fIlistelm\fR. .sp .LP The macro \fBCIRCLEQ_REMOVE()\fR removes the element \fIelm\fR from the circular queue. .sp .LP The macro \fBCIRCLEQ_EMPTY()\fR return true if the circular queue head has no elements. .sp .LP The macro \fBCIRCLEQ_FIRST()\fR returns the first element of the circular queue head. .sp .LP The macro \fBCIRCLEQ_FOREACH()\fR traverses the circle queue referenced by head in the forward direction, assigning each element in turn to \fIvar\fR. Each element is assigned exactly once. .sp .LP The macro \fBCIRCLEQ_FOREACH_REVERSE()\fR traverses the circle queue referenced by head in the reverse direction, assigning each element in turn to \fIvar\fR. Each element is assigned exactly once. .sp .LP The macro \fBCIRCLEQ_LAST()\fR returns the last element of the circular queue head. .sp .LP The macro \fBCIRCLEQ_NEXT()\fR returns the element after the element \fIelm\fR. .sp .LP The macro \fBCIRCLEQ_PREV()\fR returns the element before the element \fIelm\fR. .sp .LP The macro \fBCIRCLEQ_LOOP_NEXT()\fR returns the element after the element \fIelm\fR. If elm was the last element in the queue, the first element is returned. .sp .LP The macro \fBCIRCLEQ_LOOP_PREV()\fR returns the element before the element \fIelm\fR. If elm was the first element in the queue, the last element is returned. .SS "Circular Queue Example" .sp .in +2 .nf CIRCLEQ_HEAD(circleq, entry) head; struct circleq *headp; /* Circular queue head. */ struct entry { ... CIRCLEQ_ENTRY(entry) entries; /* Circular queue. */ ... } *n1, *n2, *np; CIRCLEQ_INIT(&head); /* Initialize circular queue. */ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ CIRCLEQ_INSERT_HEAD(&head, n1, entries); n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ CIRCLEQ_INSERT_TAIL(&head, n1, entries); n2 = malloc(sizeof(struct entry)); /* Insert after. */ CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries); n2 = malloc(sizeof(struct entry)); /* Insert before. */ CIRCLEQ_INSERT_BEFORE(&head, n1, n2, entries); /* Forward traversal. */ CIRCLEQ_FOREACH(np, &head, entries) np-> ... /* Reverse traversal. */ CIRCLEQ_FOREACH_REVERSE(np, &head, entries) np-> ... /* Delete. */ while (CIRCLEQ_FIRST(&head) != (void *)&head) CIRCLEQ_REMOVE(&head, CIRCLEQ_FIRST(&head), entries); if (CIRCLEQ_EMPTY(&head)) /* Test for emptiness. */ printf("nothing to do\en"); .fi .in -2 .sp .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .TS tab( ) box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed .TE .sp .SH SEE ALSO .sp .LP \fBqueue\fR(3EXT), \fBattributes\fR(7) .SH NOTES .sp .LP Some of these macros or functions perform no error checking, and invalid usage leads to undefined behavior. In the case of macros or functions that expect their arguments to be elements that are present in the list or queue, passing an element that is not present is invalid. .sp .LP The queue functions first appeared in 4.4BSD. The \fBSIMPLEQ\fR functions first appeared in NetBSD 1.2. The \fBSLIST\fR and \fBSTAILQ\fR functions first appeared in FreeBSD 2.1.5. The \fBCIRCLEQ_LOOP\fR functions first appeared in NetBSD 4.0.