1*27b03b36SApple OSS Distributions.\" Copyright (c) 1993 2*27b03b36SApple OSS Distributions.\" The Regents of the University of California. All rights reserved. 3*27b03b36SApple OSS Distributions.\" 4*27b03b36SApple OSS Distributions.\" Redistribution and use in source and binary forms, with or without 5*27b03b36SApple OSS Distributions.\" modification, are permitted provided that the following conditions 6*27b03b36SApple OSS Distributions.\" are met: 7*27b03b36SApple OSS Distributions.\" 1. Redistributions of source code must retain the above copyright 8*27b03b36SApple OSS Distributions.\" notice, this list of conditions and the following disclaimer. 9*27b03b36SApple OSS Distributions.\" 2. Redistributions in binary form must reproduce the above copyright 10*27b03b36SApple OSS Distributions.\" notice, this list of conditions and the following disclaimer in the 11*27b03b36SApple OSS Distributions.\" documentation and/or other materials provided with the distribution. 12*27b03b36SApple OSS Distributions.\" 3. All advertising materials mentioning features or use of this software 13*27b03b36SApple OSS Distributions.\" must display the following acknowledgement: 14*27b03b36SApple OSS Distributions.\" This product includes software developed by the University of 15*27b03b36SApple OSS Distributions.\" California, Berkeley and its contributors. 16*27b03b36SApple OSS Distributions.\" 4. Neither the name of the University nor the names of its contributors 17*27b03b36SApple OSS Distributions.\" may be used to endorse or promote products derived from this software 18*27b03b36SApple OSS Distributions.\" without specific prior written permission. 19*27b03b36SApple OSS Distributions.\" 20*27b03b36SApple OSS Distributions.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21*27b03b36SApple OSS Distributions.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22*27b03b36SApple OSS Distributions.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23*27b03b36SApple OSS Distributions.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24*27b03b36SApple OSS Distributions.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25*27b03b36SApple OSS Distributions.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26*27b03b36SApple OSS Distributions.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27*27b03b36SApple OSS Distributions.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28*27b03b36SApple OSS Distributions.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29*27b03b36SApple OSS Distributions.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30*27b03b36SApple OSS Distributions.\" SUCH DAMAGE. 31*27b03b36SApple OSS Distributions.\" 32*27b03b36SApple OSS Distributions.\" @(#)queue.3 8.2 (Berkeley) 1/24/94 33*27b03b36SApple OSS Distributions.\" $FreeBSD: /repoman/r/ncvs/src/share/man/man3/queue.3,v 1.37 2006/03/22 02:40:38 mckusick Exp $ 34*27b03b36SApple OSS Distributions.\" 35*27b03b36SApple OSS Distributions.Dd January 24, 1994 36*27b03b36SApple OSS Distributions.Dt QUEUE 3 37*27b03b36SApple OSS Distributions.Os 38*27b03b36SApple OSS Distributions.Sh NAME 39*27b03b36SApple OSS Distributions.Nm SLIST_EMPTY , 40*27b03b36SApple OSS Distributions.Nm SLIST_ENTRY , 41*27b03b36SApple OSS Distributions.Nm SLIST_FIRST , 42*27b03b36SApple OSS Distributions.Nm SLIST_FOREACH , 43*27b03b36SApple OSS Distributions.Nm SLIST_FOREACH_SAFE , 44*27b03b36SApple OSS Distributions.Nm SLIST_HEAD , 45*27b03b36SApple OSS Distributions.Nm SLIST_HEAD_INITIALIZER , 46*27b03b36SApple OSS Distributions.Nm SLIST_INIT , 47*27b03b36SApple OSS Distributions.Nm SLIST_INSERT_AFTER , 48*27b03b36SApple OSS Distributions.Nm SLIST_INSERT_HEAD , 49*27b03b36SApple OSS Distributions.Nm SLIST_NEXT , 50*27b03b36SApple OSS Distributions.Nm SLIST_REMOVE_HEAD , 51*27b03b36SApple OSS Distributions.Nm SLIST_REMOVE , 52*27b03b36SApple OSS Distributions.Nm STAILQ_CONCAT , 53*27b03b36SApple OSS Distributions.Nm STAILQ_EMPTY , 54*27b03b36SApple OSS Distributions.Nm STAILQ_ENTRY , 55*27b03b36SApple OSS Distributions.Nm STAILQ_FIRST , 56*27b03b36SApple OSS Distributions.Nm STAILQ_FOREACH , 57*27b03b36SApple OSS Distributions.Nm STAILQ_FOREACH_SAFE , 58*27b03b36SApple OSS Distributions.Nm STAILQ_HEAD , 59*27b03b36SApple OSS Distributions.Nm STAILQ_HEAD_INITIALIZER , 60*27b03b36SApple OSS Distributions.Nm STAILQ_INIT , 61*27b03b36SApple OSS Distributions.Nm STAILQ_INSERT_AFTER , 62*27b03b36SApple OSS Distributions.Nm STAILQ_INSERT_HEAD , 63*27b03b36SApple OSS Distributions.Nm STAILQ_INSERT_TAIL , 64*27b03b36SApple OSS Distributions.Nm STAILQ_LAST , 65*27b03b36SApple OSS Distributions.Nm STAILQ_NEXT , 66*27b03b36SApple OSS Distributions.Nm STAILQ_REMOVE_HEAD , 67*27b03b36SApple OSS Distributions.Nm STAILQ_REMOVE , 68*27b03b36SApple OSS Distributions.Nm LIST_EMPTY , 69*27b03b36SApple OSS Distributions.Nm LIST_ENTRY , 70*27b03b36SApple OSS Distributions.Nm LIST_FIRST , 71*27b03b36SApple OSS Distributions.Nm LIST_FOREACH , 72*27b03b36SApple OSS Distributions.Nm LIST_FOREACH_SAFE , 73*27b03b36SApple OSS Distributions.Nm LIST_HEAD , 74*27b03b36SApple OSS Distributions.Nm LIST_HEAD_INITIALIZER , 75*27b03b36SApple OSS Distributions.Nm LIST_INIT , 76*27b03b36SApple OSS Distributions.Nm LIST_INSERT_AFTER , 77*27b03b36SApple OSS Distributions.Nm LIST_INSERT_BEFORE , 78*27b03b36SApple OSS Distributions.Nm LIST_INSERT_HEAD , 79*27b03b36SApple OSS Distributions.Nm LIST_NEXT , 80*27b03b36SApple OSS Distributions.Nm LIST_REMOVE , 81*27b03b36SApple OSS Distributions.Nm TAILQ_CONCAT , 82*27b03b36SApple OSS Distributions.Nm TAILQ_EMPTY , 83*27b03b36SApple OSS Distributions.Nm TAILQ_ENTRY , 84*27b03b36SApple OSS Distributions.Nm TAILQ_FIRST , 85*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH , 86*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH_SAFE , 87*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH_REVERSE , 88*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH_REVERSE_SAFE , 89*27b03b36SApple OSS Distributions.Nm TAILQ_HEAD , 90*27b03b36SApple OSS Distributions.Nm TAILQ_HEAD_INITIALIZER , 91*27b03b36SApple OSS Distributions.Nm TAILQ_INIT , 92*27b03b36SApple OSS Distributions.Nm TAILQ_INSERT_AFTER , 93*27b03b36SApple OSS Distributions.Nm TAILQ_INSERT_BEFORE , 94*27b03b36SApple OSS Distributions.Nm TAILQ_INSERT_HEAD , 95*27b03b36SApple OSS Distributions.Nm TAILQ_INSERT_TAIL , 96*27b03b36SApple OSS Distributions.Nm TAILQ_LAST , 97*27b03b36SApple OSS Distributions.Nm TAILQ_NEXT , 98*27b03b36SApple OSS Distributions.Nm TAILQ_PREV , 99*27b03b36SApple OSS Distributions.Nm TAILQ_REMOVE 100*27b03b36SApple OSS Distributions.Nd implementations of singly-linked lists, singly-linked tail queues, 101*27b03b36SApple OSS Distributionslists and tail queues 102*27b03b36SApple OSS Distributions.Sh SYNOPSIS 103*27b03b36SApple OSS Distributions.In sys/queue.h 104*27b03b36SApple OSS Distributions.\" 105*27b03b36SApple OSS Distributions.Fn SLIST_EMPTY "SLIST_HEAD *head" 106*27b03b36SApple OSS Distributions.Fn SLIST_ENTRY "TYPE" 107*27b03b36SApple OSS Distributions.Fn SLIST_FIRST "SLIST_HEAD *head" 108*27b03b36SApple OSS Distributions.Fn SLIST_FOREACH "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" 109*27b03b36SApple OSS Distributions.Fn SLIST_FOREACH_SAFE "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" "TYPE *temp_var" 110*27b03b36SApple OSS Distributions.Fn SLIST_HEAD "HEADNAME" "TYPE" 111*27b03b36SApple OSS Distributions.Fn SLIST_HEAD_INITIALIZER "SLIST_HEAD head" 112*27b03b36SApple OSS Distributions.Fn SLIST_INIT "SLIST_HEAD *head" 113*27b03b36SApple OSS Distributions.Fn SLIST_INSERT_AFTER "TYPE *listelm" "TYPE *elm" "SLIST_ENTRY NAME" 114*27b03b36SApple OSS Distributions.Fn SLIST_INSERT_HEAD "SLIST_HEAD *head" "TYPE *elm" "SLIST_ENTRY NAME" 115*27b03b36SApple OSS Distributions.Fn SLIST_NEXT "TYPE *elm" "SLIST_ENTRY NAME" 116*27b03b36SApple OSS Distributions.Fn SLIST_REMOVE_HEAD "SLIST_HEAD *head" "SLIST_ENTRY NAME" 117*27b03b36SApple OSS Distributions.Fn SLIST_REMOVE "SLIST_HEAD *head" "TYPE *elm" "TYPE" "SLIST_ENTRY NAME" 118*27b03b36SApple OSS Distributions.\" 119*27b03b36SApple OSS Distributions.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" 120*27b03b36SApple OSS Distributions.Fn STAILQ_EMPTY "STAILQ_HEAD *head" 121*27b03b36SApple OSS Distributions.Fn STAILQ_ENTRY "TYPE" 122*27b03b36SApple OSS Distributions.Fn STAILQ_FIRST "STAILQ_HEAD *head" 123*27b03b36SApple OSS Distributions.Fn STAILQ_FOREACH "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" 124*27b03b36SApple OSS Distributions.Fn STAILQ_FOREACH_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var" 125*27b03b36SApple OSS Distributions.Fn STAILQ_HEAD "HEADNAME" "TYPE" 126*27b03b36SApple OSS Distributions.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head" 127*27b03b36SApple OSS Distributions.Fn STAILQ_INIT "STAILQ_HEAD *head" 128*27b03b36SApple OSS Distributions.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "STAILQ_ENTRY NAME" 129*27b03b36SApple OSS Distributions.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME" 130*27b03b36SApple OSS Distributions.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME" 131*27b03b36SApple OSS Distributions.Fn STAILQ_LAST "STAILQ_HEAD *head" "TYPE" "STAILQ_ENTRY NAME" 132*27b03b36SApple OSS Distributions.Fn STAILQ_NEXT "TYPE *elm" "STAILQ_ENTRY NAME" 133*27b03b36SApple OSS Distributions.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" 134*27b03b36SApple OSS Distributions.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "TYPE *elm" "TYPE" "STAILQ_ENTRY NAME" 135*27b03b36SApple OSS Distributions.\" 136*27b03b36SApple OSS Distributions.Fn LIST_EMPTY "LIST_HEAD *head" 137*27b03b36SApple OSS Distributions.Fn LIST_ENTRY "TYPE" 138*27b03b36SApple OSS Distributions.Fn LIST_FIRST "LIST_HEAD *head" 139*27b03b36SApple OSS Distributions.Fn LIST_FOREACH "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" 140*27b03b36SApple OSS Distributions.Fn LIST_FOREACH_SAFE "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" "TYPE *temp_var" 141*27b03b36SApple OSS Distributions.Fn LIST_HEAD "HEADNAME" "TYPE" 142*27b03b36SApple OSS Distributions.Fn LIST_HEAD_INITIALIZER "LIST_HEAD head" 143*27b03b36SApple OSS Distributions.Fn LIST_INIT "LIST_HEAD *head" 144*27b03b36SApple OSS Distributions.Fn LIST_INSERT_AFTER "TYPE *listelm" "TYPE *elm" "LIST_ENTRY NAME" 145*27b03b36SApple OSS Distributions.Fn LIST_INSERT_BEFORE "TYPE *listelm" "TYPE *elm" "LIST_ENTRY NAME" 146*27b03b36SApple OSS Distributions.Fn LIST_INSERT_HEAD "LIST_HEAD *head" "TYPE *elm" "LIST_ENTRY NAME" 147*27b03b36SApple OSS Distributions.Fn LIST_NEXT "TYPE *elm" "LIST_ENTRY NAME" 148*27b03b36SApple OSS Distributions.Fn LIST_REMOVE "TYPE *elm" "LIST_ENTRY NAME" 149*27b03b36SApple OSS Distributions.\" 150*27b03b36SApple OSS Distributions.Fn TAILQ_CONCAT "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TAILQ_ENTRY NAME" 151*27b03b36SApple OSS Distributions.Fn TAILQ_EMPTY "TAILQ_HEAD *head" 152*27b03b36SApple OSS Distributions.Fn TAILQ_ENTRY "TYPE" 153*27b03b36SApple OSS Distributions.Fn TAILQ_FIRST "TAILQ_HEAD *head" 154*27b03b36SApple OSS Distributions.Fn TAILQ_FOREACH "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" 155*27b03b36SApple OSS Distributions.Fn TAILQ_FOREACH_SAFE "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" "TYPE *temp_var" 156*27b03b36SApple OSS Distributions.Fn TAILQ_FOREACH_REVERSE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" 157*27b03b36SApple OSS Distributions.Fn TAILQ_FOREACH_REVERSE_SAFE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" "TYPE *temp_var" 158*27b03b36SApple OSS Distributions.Fn TAILQ_HEAD "HEADNAME" "TYPE" 159*27b03b36SApple OSS Distributions.Fn TAILQ_HEAD_INITIALIZER "TAILQ_HEAD head" 160*27b03b36SApple OSS Distributions.Fn TAILQ_INIT "TAILQ_HEAD *head" 161*27b03b36SApple OSS Distributions.Fn TAILQ_INSERT_AFTER "TAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "TAILQ_ENTRY NAME" 162*27b03b36SApple OSS Distributions.Fn TAILQ_INSERT_BEFORE "TYPE *listelm" "TYPE *elm" "TAILQ_ENTRY NAME" 163*27b03b36SApple OSS Distributions.Fn TAILQ_INSERT_HEAD "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME" 164*27b03b36SApple OSS Distributions.Fn TAILQ_INSERT_TAIL "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME" 165*27b03b36SApple OSS Distributions.Fn TAILQ_LAST "TAILQ_HEAD *head" "HEADNAME" 166*27b03b36SApple OSS Distributions.Fn TAILQ_NEXT "TYPE *elm" "TAILQ_ENTRY NAME" 167*27b03b36SApple OSS Distributions.Fn TAILQ_PREV "TYPE *elm" "HEADNAME" "TAILQ_ENTRY NAME" 168*27b03b36SApple OSS Distributions.Fn TAILQ_REMOVE "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME" 169*27b03b36SApple OSS Distributions.\" 170*27b03b36SApple OSS Distributions.Sh DESCRIPTION 171*27b03b36SApple OSS DistributionsThese macros define and operate on four types of data structures: 172*27b03b36SApple OSS Distributionssingly-linked lists, singly-linked tail queues, lists, and tail queues. 173*27b03b36SApple OSS DistributionsAll four structures support the following functionality: 174*27b03b36SApple OSS Distributions.Bl -enum -compact -offset indent 175*27b03b36SApple OSS Distributions.It 176*27b03b36SApple OSS DistributionsInsertion of a new entry at the head of the list. 177*27b03b36SApple OSS Distributions.It 178*27b03b36SApple OSS DistributionsInsertion of a new entry after any element in the list. 179*27b03b36SApple OSS Distributions.It 180*27b03b36SApple OSS DistributionsO(1) removal of an entry from the head of the list. 181*27b03b36SApple OSS Distributions.It 182*27b03b36SApple OSS DistributionsO(n) removal of any entry in the list. 183*27b03b36SApple OSS Distributions.It 184*27b03b36SApple OSS DistributionsForward traversal through the list. 185*27b03b36SApple OSS Distributions.El 186*27b03b36SApple OSS Distributions.Pp 187*27b03b36SApple OSS DistributionsSingly-linked lists are the simplest of the five data structures 188*27b03b36SApple OSS Distributionsand support only the above functionality. 189*27b03b36SApple OSS DistributionsSingly-linked lists are ideal for applications with large datasets 190*27b03b36SApple OSS Distributionsand few or no removals, 191*27b03b36SApple OSS Distributionsor for implementing a LIFO queue. 192*27b03b36SApple OSS Distributions.Pp 193*27b03b36SApple OSS DistributionsSingly-linked tail queues add the following functionality: 194*27b03b36SApple OSS Distributions.Bl -enum -compact -offset indent 195*27b03b36SApple OSS Distributions.It 196*27b03b36SApple OSS DistributionsEntries can be added at the end of a list. 197*27b03b36SApple OSS Distributions.It 198*27b03b36SApple OSS DistributionsThey may be concatenated. 199*27b03b36SApple OSS Distributions.El 200*27b03b36SApple OSS DistributionsHowever: 201*27b03b36SApple OSS Distributions.Bl -enum -compact -offset indent 202*27b03b36SApple OSS Distributions.It 203*27b03b36SApple OSS DistributionsAll list insertions must specify the head of the list. 204*27b03b36SApple OSS Distributions.It 205*27b03b36SApple OSS DistributionsEach head entry requires two pointers rather than one. 206*27b03b36SApple OSS Distributions.It 207*27b03b36SApple OSS DistributionsCode size is about 15% greater and operations run about 20% slower 208*27b03b36SApple OSS Distributionsthan singly-linked lists. 209*27b03b36SApple OSS Distributions.El 210*27b03b36SApple OSS Distributions.Pp 211*27b03b36SApple OSS DistributionsSingly-linked tailqs are ideal for applications with large datasets and 212*27b03b36SApple OSS Distributionsfew or no removals, 213*27b03b36SApple OSS Distributionsor for implementing a FIFO queue. 214*27b03b36SApple OSS Distributions.Pp 215*27b03b36SApple OSS DistributionsAll doubly linked types of data structures (lists and tail queues) 216*27b03b36SApple OSS Distributionsadditionally allow: 217*27b03b36SApple OSS Distributions.Bl -enum -compact -offset indent 218*27b03b36SApple OSS Distributions.It 219*27b03b36SApple OSS DistributionsInsertion of a new entry before any element in the list. 220*27b03b36SApple OSS Distributions.It 221*27b03b36SApple OSS DistributionsO(1) removal of any entry in the list. 222*27b03b36SApple OSS Distributions.El 223*27b03b36SApple OSS DistributionsHowever: 224*27b03b36SApple OSS Distributions.Bl -enum -compact -offset indent 225*27b03b36SApple OSS Distributions.It 226*27b03b36SApple OSS DistributionsEach elements requires two pointers rather than one. 227*27b03b36SApple OSS Distributions.It 228*27b03b36SApple OSS DistributionsCode size and execution time of operations (except for removal) is about 229*27b03b36SApple OSS Distributionstwice that of the singly-linked data-structures. 230*27b03b36SApple OSS Distributions.El 231*27b03b36SApple OSS Distributions.Pp 232*27b03b36SApple OSS DistributionsLinked lists are the simplest of the doubly linked data structures and support 233*27b03b36SApple OSS Distributionsonly the above functionality over singly-linked lists. 234*27b03b36SApple OSS Distributions.Pp 235*27b03b36SApple OSS DistributionsTail queues add the following functionality: 236*27b03b36SApple OSS Distributions.Bl -enum -compact -offset indent 237*27b03b36SApple OSS Distributions.It 238*27b03b36SApple OSS DistributionsEntries can be added at the end of a list. 239*27b03b36SApple OSS Distributions.It 240*27b03b36SApple OSS DistributionsThey may be traversed backwards, from tail to head. 241*27b03b36SApple OSS Distributions.It 242*27b03b36SApple OSS DistributionsThey may be concatenated. 243*27b03b36SApple OSS Distributions.El 244*27b03b36SApple OSS DistributionsHowever: 245*27b03b36SApple OSS Distributions.Bl -enum -compact -offset indent 246*27b03b36SApple OSS Distributions.It 247*27b03b36SApple OSS DistributionsAll list insertions and removals must specify the head of the list. 248*27b03b36SApple OSS Distributions.It 249*27b03b36SApple OSS DistributionsEach head entry requires two pointers rather than one. 250*27b03b36SApple OSS Distributions.It 251*27b03b36SApple OSS DistributionsCode size is about 15% greater and operations run about 20% slower 252*27b03b36SApple OSS Distributionsthan singly-linked lists. 253*27b03b36SApple OSS Distributions.El 254*27b03b36SApple OSS Distributions.Pp 255*27b03b36SApple OSS DistributionsIn the macro definitions, 256*27b03b36SApple OSS Distributions.Fa TYPE 257*27b03b36SApple OSS Distributionsis the name of a user defined structure, 258*27b03b36SApple OSS Distributionsthat must contain a field of type 259*27b03b36SApple OSS Distributions.Li SLIST_ENTRY , 260*27b03b36SApple OSS Distributions.Li STAILQ_ENTRY , 261*27b03b36SApple OSS Distributions.Li LIST_ENTRY , 262*27b03b36SApple OSS Distributionsor 263*27b03b36SApple OSS Distributions.Li TAILQ_ENTRY , 264*27b03b36SApple OSS Distributionsnamed 265*27b03b36SApple OSS Distributions.Fa NAME . 266*27b03b36SApple OSS DistributionsThe argument 267*27b03b36SApple OSS Distributions.Fa HEADNAME 268*27b03b36SApple OSS Distributionsis the name of a user defined structure that must be declared 269*27b03b36SApple OSS Distributionsusing the macros 270*27b03b36SApple OSS Distributions.Li SLIST_HEAD , 271*27b03b36SApple OSS Distributions.Li STAILQ_HEAD , 272*27b03b36SApple OSS Distributions.Li LIST_HEAD , 273*27b03b36SApple OSS Distributionsor 274*27b03b36SApple OSS Distributions.Li TAILQ_HEAD . 275*27b03b36SApple OSS DistributionsSee the examples below for further explanation of how these 276*27b03b36SApple OSS Distributionsmacros are used. 277*27b03b36SApple OSS Distributions.Sh SINGLY-LINKED LISTS 278*27b03b36SApple OSS DistributionsA singly-linked list is headed by a structure defined by the 279*27b03b36SApple OSS Distributions.Nm SLIST_HEAD 280*27b03b36SApple OSS Distributionsmacro. 281*27b03b36SApple OSS DistributionsThis structure contains a single pointer to the first element 282*27b03b36SApple OSS Distributionson the list. 283*27b03b36SApple OSS DistributionsThe elements are singly linked for minimum space and pointer manipulation 284*27b03b36SApple OSS Distributionsoverhead at the expense of O(n) removal for arbitrary elements. 285*27b03b36SApple OSS DistributionsNew elements can be added to the list after an existing element or 286*27b03b36SApple OSS Distributionsat the head of the list. 287*27b03b36SApple OSS DistributionsAn 288*27b03b36SApple OSS Distributions.Fa SLIST_HEAD 289*27b03b36SApple OSS Distributionsstructure is declared as follows: 290*27b03b36SApple OSS Distributions.Bd -literal -offset indent 291*27b03b36SApple OSS DistributionsSLIST_HEAD(HEADNAME, TYPE) head; 292*27b03b36SApple OSS Distributions.Ed 293*27b03b36SApple OSS Distributions.Pp 294*27b03b36SApple OSS Distributionswhere 295*27b03b36SApple OSS Distributions.Fa HEADNAME 296*27b03b36SApple OSS Distributionsis the name of the structure to be defined, and 297*27b03b36SApple OSS Distributions.Fa TYPE 298*27b03b36SApple OSS Distributionsis the type of the elements to be linked into the list. 299*27b03b36SApple OSS DistributionsA pointer to the head of the list can later be declared as: 300*27b03b36SApple OSS Distributions.Bd -literal -offset indent 301*27b03b36SApple OSS Distributionsstruct HEADNAME *headp; 302*27b03b36SApple OSS Distributions.Ed 303*27b03b36SApple OSS Distributions.Pp 304*27b03b36SApple OSS Distributions(The names 305*27b03b36SApple OSS Distributions.Li head 306*27b03b36SApple OSS Distributionsand 307*27b03b36SApple OSS Distributions.Li headp 308*27b03b36SApple OSS Distributionsare user selectable.) 309*27b03b36SApple OSS Distributions.Pp 310*27b03b36SApple OSS DistributionsThe macro 311*27b03b36SApple OSS Distributions.Nm SLIST_HEAD_INITIALIZER 312*27b03b36SApple OSS Distributionsevaluates to an initializer for the list 313*27b03b36SApple OSS Distributions.Fa head . 314*27b03b36SApple OSS Distributions.Pp 315*27b03b36SApple OSS DistributionsThe macro 316*27b03b36SApple OSS Distributions.Nm SLIST_EMPTY 317*27b03b36SApple OSS Distributionsevaluates to true if there are no elements in the list. 318*27b03b36SApple OSS Distributions.Pp 319*27b03b36SApple OSS DistributionsThe macro 320*27b03b36SApple OSS Distributions.Nm SLIST_ENTRY 321*27b03b36SApple OSS Distributionsdeclares a structure that connects the elements in 322*27b03b36SApple OSS Distributionsthe list. 323*27b03b36SApple OSS Distributions.Pp 324*27b03b36SApple OSS DistributionsThe macro 325*27b03b36SApple OSS Distributions.Nm SLIST_FIRST 326*27b03b36SApple OSS Distributionsreturns the first element in the list or NULL if the list is empty. 327*27b03b36SApple OSS Distributions.Pp 328*27b03b36SApple OSS DistributionsThe macro 329*27b03b36SApple OSS Distributions.Nm SLIST_FOREACH 330*27b03b36SApple OSS Distributionstraverses the list referenced by 331*27b03b36SApple OSS Distributions.Fa head 332*27b03b36SApple OSS Distributionsin the forward direction, assigning each element in 333*27b03b36SApple OSS Distributionsturn to 334*27b03b36SApple OSS Distributions.Fa var . 335*27b03b36SApple OSS Distributions.Pp 336*27b03b36SApple OSS DistributionsThe macro 337*27b03b36SApple OSS Distributions.Nm SLIST_FOREACH_SAFE 338*27b03b36SApple OSS Distributionstraverses the list referenced by 339*27b03b36SApple OSS Distributions.Fa head 340*27b03b36SApple OSS Distributionsin the forward direction, assigning each element in 341*27b03b36SApple OSS Distributionsturn to 342*27b03b36SApple OSS Distributions.Fa var . 343*27b03b36SApple OSS DistributionsHowever, unlike 344*27b03b36SApple OSS Distributions.Fn SLIST_FOREACH 345*27b03b36SApple OSS Distributionshere it is permitted to both remove 346*27b03b36SApple OSS Distributions.Fa var 347*27b03b36SApple OSS Distributionsas well as free it from within the loop safely without interfering with the 348*27b03b36SApple OSS Distributionstraversal. 349*27b03b36SApple OSS Distributions.Pp 350*27b03b36SApple OSS DistributionsThe macro 351*27b03b36SApple OSS Distributions.Nm SLIST_INIT 352*27b03b36SApple OSS Distributionsinitializes the list referenced by 353*27b03b36SApple OSS Distributions.Fa head . 354*27b03b36SApple OSS Distributions.Pp 355*27b03b36SApple OSS DistributionsThe macro 356*27b03b36SApple OSS Distributions.Nm SLIST_INSERT_HEAD 357*27b03b36SApple OSS Distributionsinserts the new element 358*27b03b36SApple OSS Distributions.Fa elm 359*27b03b36SApple OSS Distributionsat the head of the list. 360*27b03b36SApple OSS Distributions.Pp 361*27b03b36SApple OSS DistributionsThe macro 362*27b03b36SApple OSS Distributions.Nm SLIST_INSERT_AFTER 363*27b03b36SApple OSS Distributionsinserts the new element 364*27b03b36SApple OSS Distributions.Fa elm 365*27b03b36SApple OSS Distributionsafter the element 366*27b03b36SApple OSS Distributions.Fa listelm . 367*27b03b36SApple OSS Distributions.Pp 368*27b03b36SApple OSS DistributionsThe macro 369*27b03b36SApple OSS Distributions.Nm SLIST_NEXT 370*27b03b36SApple OSS Distributionsreturns the next element in the list. 371*27b03b36SApple OSS Distributions.Pp 372*27b03b36SApple OSS DistributionsThe macro 373*27b03b36SApple OSS Distributions.Nm SLIST_REMOVE_HEAD 374*27b03b36SApple OSS Distributionsremoves the element 375*27b03b36SApple OSS Distributions.Fa elm 376*27b03b36SApple OSS Distributionsfrom the head of the list. 377*27b03b36SApple OSS DistributionsFor optimum efficiency, 378*27b03b36SApple OSS Distributionselements being removed from the head of the list should explicitly use 379*27b03b36SApple OSS Distributionsthis macro instead of the generic 380*27b03b36SApple OSS Distributions.Fa SLIST_REMOVE 381*27b03b36SApple OSS Distributionsmacro. 382*27b03b36SApple OSS Distributions.Pp 383*27b03b36SApple OSS DistributionsThe macro 384*27b03b36SApple OSS Distributions.Nm SLIST_REMOVE 385*27b03b36SApple OSS Distributionsremoves the element 386*27b03b36SApple OSS Distributions.Fa elm 387*27b03b36SApple OSS Distributionsfrom the list. 388*27b03b36SApple OSS Distributions.Sh SINGLY-LINKED LIST EXAMPLE 389*27b03b36SApple OSS Distributions.Bd -literal 390*27b03b36SApple OSS DistributionsSLIST_HEAD(slisthead, entry) head = 391*27b03b36SApple OSS Distributions SLIST_HEAD_INITIALIZER(head); 392*27b03b36SApple OSS Distributionsstruct slisthead *headp; /* Singly-linked List head. */ 393*27b03b36SApple OSS Distributionsstruct entry { 394*27b03b36SApple OSS Distributions ... 395*27b03b36SApple OSS Distributions SLIST_ENTRY(entry) entries; /* Singly-linked List. */ 396*27b03b36SApple OSS Distributions ... 397*27b03b36SApple OSS Distributions} *n1, *n2, *n3, *np; 398*27b03b36SApple OSS Distributions 399*27b03b36SApple OSS DistributionsSLIST_INIT(&head); /* Initialize the list. */ 400*27b03b36SApple OSS Distributions 401*27b03b36SApple OSS Distributionsn1 = malloc(sizeof(struct entry)); /* Insert at the head. */ 402*27b03b36SApple OSS DistributionsSLIST_INSERT_HEAD(&head, n1, entries); 403*27b03b36SApple OSS Distributions 404*27b03b36SApple OSS Distributionsn2 = malloc(sizeof(struct entry)); /* Insert after. */ 405*27b03b36SApple OSS DistributionsSLIST_INSERT_AFTER(n1, n2, entries); 406*27b03b36SApple OSS Distributions 407*27b03b36SApple OSS DistributionsSLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */ 408*27b03b36SApple OSS Distributionsfree(n2); 409*27b03b36SApple OSS Distributions 410*27b03b36SApple OSS Distributionsn3 = SLIST_FIRST(&head); 411*27b03b36SApple OSS DistributionsSLIST_REMOVE_HEAD(&head, entries); /* Deletion from the head. */ 412*27b03b36SApple OSS Distributionsfree(n3); 413*27b03b36SApple OSS Distributions /* Forward traversal. */ 414*27b03b36SApple OSS DistributionsSLIST_FOREACH(np, &head, entries) 415*27b03b36SApple OSS Distributions np-> ... 416*27b03b36SApple OSS Distributions /* Safe forward traversal. */ 417*27b03b36SApple OSS DistributionsSLIST_FOREACH_SAFE(np, &head, entries, np_temp) { 418*27b03b36SApple OSS Distributions np->do_stuff(); 419*27b03b36SApple OSS Distributions ... 420*27b03b36SApple OSS Distributions SLIST_REMOVE(&head, np, entry, entries); 421*27b03b36SApple OSS Distributions free(np); 422*27b03b36SApple OSS Distributions} 423*27b03b36SApple OSS Distributions 424*27b03b36SApple OSS Distributionswhile (!SLIST_EMPTY(&head)) { /* List Deletion. */ 425*27b03b36SApple OSS Distributions n1 = SLIST_FIRST(&head); 426*27b03b36SApple OSS Distributions SLIST_REMOVE_HEAD(&head, entries); 427*27b03b36SApple OSS Distributions free(n1); 428*27b03b36SApple OSS Distributions} 429*27b03b36SApple OSS Distributions.Ed 430*27b03b36SApple OSS Distributions.Sh SINGLY-LINKED TAIL QUEUES 431*27b03b36SApple OSS DistributionsA singly-linked tail queue is headed by a structure defined by the 432*27b03b36SApple OSS Distributions.Nm STAILQ_HEAD 433*27b03b36SApple OSS Distributionsmacro. 434*27b03b36SApple OSS DistributionsThis structure contains a pair of pointers, 435*27b03b36SApple OSS Distributionsone to the first element in the tail queue and the other to 436*27b03b36SApple OSS Distributionsthe last element in the tail queue. 437*27b03b36SApple OSS DistributionsThe elements are singly linked for minimum space and pointer 438*27b03b36SApple OSS Distributionsmanipulation overhead at the expense of O(n) removal for arbitrary 439*27b03b36SApple OSS Distributionselements. 440*27b03b36SApple OSS DistributionsNew elements can be added to the tail queue after an existing element, 441*27b03b36SApple OSS Distributionsat the head of the tail queue, or at the end of the tail queue. 442*27b03b36SApple OSS DistributionsA 443*27b03b36SApple OSS Distributions.Fa STAILQ_HEAD 444*27b03b36SApple OSS Distributionsstructure is declared as follows: 445*27b03b36SApple OSS Distributions.Bd -literal -offset indent 446*27b03b36SApple OSS DistributionsSTAILQ_HEAD(HEADNAME, TYPE) head; 447*27b03b36SApple OSS Distributions.Ed 448*27b03b36SApple OSS Distributions.Pp 449*27b03b36SApple OSS Distributionswhere 450*27b03b36SApple OSS Distributions.Li HEADNAME 451*27b03b36SApple OSS Distributionsis the name of the structure to be defined, and 452*27b03b36SApple OSS Distributions.Li TYPE 453*27b03b36SApple OSS Distributionsis the type of the elements to be linked into the tail queue. 454*27b03b36SApple OSS DistributionsA pointer to the head of the tail queue can later be declared as: 455*27b03b36SApple OSS Distributions.Bd -literal -offset indent 456*27b03b36SApple OSS Distributionsstruct HEADNAME *headp; 457*27b03b36SApple OSS Distributions.Ed 458*27b03b36SApple OSS Distributions.Pp 459*27b03b36SApple OSS Distributions(The names 460*27b03b36SApple OSS Distributions.Li head 461*27b03b36SApple OSS Distributionsand 462*27b03b36SApple OSS Distributions.Li headp 463*27b03b36SApple OSS Distributionsare user selectable.) 464*27b03b36SApple OSS Distributions.Pp 465*27b03b36SApple OSS DistributionsThe macro 466*27b03b36SApple OSS Distributions.Nm STAILQ_HEAD_INITIALIZER 467*27b03b36SApple OSS Distributionsevaluates to an initializer for the tail queue 468*27b03b36SApple OSS Distributions.Fa head . 469*27b03b36SApple OSS Distributions.Pp 470*27b03b36SApple OSS DistributionsThe macro 471*27b03b36SApple OSS Distributions.Nm STAILQ_CONCAT 472*27b03b36SApple OSS Distributionsconcatenates the tail queue headed by 473*27b03b36SApple OSS Distributions.Fa head2 474*27b03b36SApple OSS Distributionsonto the end of the one headed by 475*27b03b36SApple OSS Distributions.Fa head1 476*27b03b36SApple OSS Distributionsremoving all entries from the former. 477*27b03b36SApple OSS Distributions.Pp 478*27b03b36SApple OSS DistributionsThe macro 479*27b03b36SApple OSS Distributions.Nm STAILQ_EMPTY 480*27b03b36SApple OSS Distributionsevaluates to true if there are no items on the tail queue. 481*27b03b36SApple OSS Distributions.Pp 482*27b03b36SApple OSS DistributionsThe macro 483*27b03b36SApple OSS Distributions.Nm STAILQ_ENTRY 484*27b03b36SApple OSS Distributionsdeclares a structure that connects the elements in 485*27b03b36SApple OSS Distributionsthe tail queue. 486*27b03b36SApple OSS Distributions.Pp 487*27b03b36SApple OSS DistributionsThe macro 488*27b03b36SApple OSS Distributions.Nm STAILQ_FIRST 489*27b03b36SApple OSS Distributionsreturns the first item on the tail queue or NULL if the tail queue 490*27b03b36SApple OSS Distributionsis empty. 491*27b03b36SApple OSS Distributions.Pp 492*27b03b36SApple OSS DistributionsThe macro 493*27b03b36SApple OSS Distributions.Nm STAILQ_FOREACH 494*27b03b36SApple OSS Distributionstraverses the tail queue referenced by 495*27b03b36SApple OSS Distributions.Fa head 496*27b03b36SApple OSS Distributionsin the forward direction, assigning each element 497*27b03b36SApple OSS Distributionsin turn to 498*27b03b36SApple OSS Distributions.Fa var . 499*27b03b36SApple OSS Distributions.Pp 500*27b03b36SApple OSS DistributionsThe macro 501*27b03b36SApple OSS Distributions.Nm STAILQ_FOREACH_SAFE 502*27b03b36SApple OSS Distributionstraverses the tail queue referenced by 503*27b03b36SApple OSS Distributions.Fa head 504*27b03b36SApple OSS Distributionsin the forward direction, assigning each element 505*27b03b36SApple OSS Distributionsin turn to 506*27b03b36SApple OSS Distributions.Fa var . 507*27b03b36SApple OSS DistributionsHowever, unlike 508*27b03b36SApple OSS Distributions.Fn STAILQ_FOREACH 509*27b03b36SApple OSS Distributionshere it is permitted to both remove 510*27b03b36SApple OSS Distributions.Fa var 511*27b03b36SApple OSS Distributionsas well as free it from within the loop safely without interfering with the 512*27b03b36SApple OSS Distributionstraversal. 513*27b03b36SApple OSS Distributions.Pp 514*27b03b36SApple OSS DistributionsThe macro 515*27b03b36SApple OSS Distributions.Nm STAILQ_INIT 516*27b03b36SApple OSS Distributionsinitializes the tail queue referenced by 517*27b03b36SApple OSS Distributions.Fa head . 518*27b03b36SApple OSS Distributions.Pp 519*27b03b36SApple OSS DistributionsThe macro 520*27b03b36SApple OSS Distributions.Nm STAILQ_INSERT_HEAD 521*27b03b36SApple OSS Distributionsinserts the new element 522*27b03b36SApple OSS Distributions.Fa elm 523*27b03b36SApple OSS Distributionsat the head of the tail queue. 524*27b03b36SApple OSS Distributions.Pp 525*27b03b36SApple OSS DistributionsThe macro 526*27b03b36SApple OSS Distributions.Nm STAILQ_INSERT_TAIL 527*27b03b36SApple OSS Distributionsinserts the new element 528*27b03b36SApple OSS Distributions.Fa elm 529*27b03b36SApple OSS Distributionsat the end of the tail queue. 530*27b03b36SApple OSS Distributions.Pp 531*27b03b36SApple OSS DistributionsThe macro 532*27b03b36SApple OSS Distributions.Nm STAILQ_INSERT_AFTER 533*27b03b36SApple OSS Distributionsinserts the new element 534*27b03b36SApple OSS Distributions.Fa elm 535*27b03b36SApple OSS Distributionsafter the element 536*27b03b36SApple OSS Distributions.Fa listelm . 537*27b03b36SApple OSS Distributions.Pp 538*27b03b36SApple OSS DistributionsThe macro 539*27b03b36SApple OSS Distributions.Nm STAILQ_LAST 540*27b03b36SApple OSS Distributionsreturns the last item on the tail queue. 541*27b03b36SApple OSS DistributionsIf the tail queue is empty the return value is NULL. 542*27b03b36SApple OSS Distributions.Pp 543*27b03b36SApple OSS DistributionsThe macro 544*27b03b36SApple OSS Distributions.Nm STAILQ_NEXT 545*27b03b36SApple OSS Distributionsreturns the next item on the tail queue, or NULL this item is the last. 546*27b03b36SApple OSS Distributions.Pp 547*27b03b36SApple OSS DistributionsThe macro 548*27b03b36SApple OSS Distributions.Nm STAILQ_REMOVE_HEAD 549*27b03b36SApple OSS Distributionsremoves the element at the head of the tail queue. 550*27b03b36SApple OSS DistributionsFor optimum efficiency, 551*27b03b36SApple OSS Distributionselements being removed from the head of the tail queue should 552*27b03b36SApple OSS Distributionsuse this macro explicitly rather than the generic 553*27b03b36SApple OSS Distributions.Fa STAILQ_REMOVE 554*27b03b36SApple OSS Distributionsmacro. 555*27b03b36SApple OSS Distributions.Pp 556*27b03b36SApple OSS DistributionsThe macro 557*27b03b36SApple OSS Distributions.Nm STAILQ_REMOVE 558*27b03b36SApple OSS Distributionsremoves the element 559*27b03b36SApple OSS Distributions.Fa elm 560*27b03b36SApple OSS Distributionsfrom the tail queue. 561*27b03b36SApple OSS Distributions.Sh SINGLY-LINKED TAIL QUEUE EXAMPLE 562*27b03b36SApple OSS Distributions.Bd -literal 563*27b03b36SApple OSS DistributionsSTAILQ_HEAD(stailhead, entry) head = 564*27b03b36SApple OSS Distributions STAILQ_HEAD_INITIALIZER(head); 565*27b03b36SApple OSS Distributionsstruct stailhead *headp; /* Singly-linked tail queue head. */ 566*27b03b36SApple OSS Distributionsstruct entry { 567*27b03b36SApple OSS Distributions ... 568*27b03b36SApple OSS Distributions STAILQ_ENTRY(entry) entries; /* Tail queue. */ 569*27b03b36SApple OSS Distributions ... 570*27b03b36SApple OSS Distributions} *n1, *n2, *n3, *np; 571*27b03b36SApple OSS Distributions 572*27b03b36SApple OSS DistributionsSTAILQ_INIT(&head); /* Initialize the queue. */ 573*27b03b36SApple OSS Distributions 574*27b03b36SApple OSS Distributionsn1 = malloc(sizeof(struct entry)); /* Insert at the head. */ 575*27b03b36SApple OSS DistributionsSTAILQ_INSERT_HEAD(&head, n1, entries); 576*27b03b36SApple OSS Distributions 577*27b03b36SApple OSS Distributionsn1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ 578*27b03b36SApple OSS DistributionsSTAILQ_INSERT_TAIL(&head, n1, entries); 579*27b03b36SApple OSS Distributions 580*27b03b36SApple OSS Distributionsn2 = malloc(sizeof(struct entry)); /* Insert after. */ 581*27b03b36SApple OSS DistributionsSTAILQ_INSERT_AFTER(&head, n1, n2, entries); 582*27b03b36SApple OSS Distributions /* Deletion. */ 583*27b03b36SApple OSS DistributionsSTAILQ_REMOVE(&head, n2, entry, entries); 584*27b03b36SApple OSS Distributionsfree(n2); 585*27b03b36SApple OSS Distributions /* Deletion from the head. */ 586*27b03b36SApple OSS Distributionsn3 = STAILQ_FIRST(&head); 587*27b03b36SApple OSS DistributionsSTAILQ_REMOVE_HEAD(&head, entries); 588*27b03b36SApple OSS Distributionsfree(n3); 589*27b03b36SApple OSS Distributions /* Forward traversal. */ 590*27b03b36SApple OSS DistributionsSTAILQ_FOREACH(np, &head, entries) 591*27b03b36SApple OSS Distributions np-> ... 592*27b03b36SApple OSS Distributions /* Safe forward traversal. */ 593*27b03b36SApple OSS DistributionsSTAILQ_FOREACH_SAFE(np, &head, entries, np_temp) { 594*27b03b36SApple OSS Distributions np->do_stuff(); 595*27b03b36SApple OSS Distributions ... 596*27b03b36SApple OSS Distributions STAILQ_REMOVE(&head, np, entry, entries); 597*27b03b36SApple OSS Distributions free(np); 598*27b03b36SApple OSS Distributions} 599*27b03b36SApple OSS Distributions /* TailQ Deletion. */ 600*27b03b36SApple OSS Distributionswhile (!STAILQ_EMPTY(&head)) { 601*27b03b36SApple OSS Distributions n1 = STAILQ_FIRST(&head); 602*27b03b36SApple OSS Distributions STAILQ_REMOVE_HEAD(&head, entries); 603*27b03b36SApple OSS Distributions free(n1); 604*27b03b36SApple OSS Distributions} 605*27b03b36SApple OSS Distributions /* Faster TailQ Deletion. */ 606*27b03b36SApple OSS Distributionsn1 = STAILQ_FIRST(&head); 607*27b03b36SApple OSS Distributionswhile (n1 != NULL) { 608*27b03b36SApple OSS Distributions n2 = STAILQ_NEXT(n1, entries); 609*27b03b36SApple OSS Distributions free(n1); 610*27b03b36SApple OSS Distributions n1 = n2; 611*27b03b36SApple OSS Distributions} 612*27b03b36SApple OSS DistributionsSTAILQ_INIT(&head); 613*27b03b36SApple OSS Distributions.Ed 614*27b03b36SApple OSS Distributions.Sh LISTS 615*27b03b36SApple OSS DistributionsA list is headed by a structure defined by the 616*27b03b36SApple OSS Distributions.Nm LIST_HEAD 617*27b03b36SApple OSS Distributionsmacro. 618*27b03b36SApple OSS DistributionsThis structure contains a single pointer to the first element 619*27b03b36SApple OSS Distributionson the list. 620*27b03b36SApple OSS DistributionsThe elements are doubly linked so that an arbitrary element can be 621*27b03b36SApple OSS Distributionsremoved without traversing the list. 622*27b03b36SApple OSS DistributionsNew elements can be added to the list after an existing element, 623*27b03b36SApple OSS Distributionsbefore an existing element, or at the head of the list. 624*27b03b36SApple OSS DistributionsA 625*27b03b36SApple OSS Distributions.Fa LIST_HEAD 626*27b03b36SApple OSS Distributionsstructure is declared as follows: 627*27b03b36SApple OSS Distributions.Bd -literal -offset indent 628*27b03b36SApple OSS DistributionsLIST_HEAD(HEADNAME, TYPE) head; 629*27b03b36SApple OSS Distributions.Ed 630*27b03b36SApple OSS Distributions.Pp 631*27b03b36SApple OSS Distributionswhere 632*27b03b36SApple OSS Distributions.Fa HEADNAME 633*27b03b36SApple OSS Distributionsis the name of the structure to be defined, and 634*27b03b36SApple OSS Distributions.Fa TYPE 635*27b03b36SApple OSS Distributionsis the type of the elements to be linked into the list. 636*27b03b36SApple OSS DistributionsA pointer to the head of the list can later be declared as: 637*27b03b36SApple OSS Distributions.Bd -literal -offset indent 638*27b03b36SApple OSS Distributionsstruct HEADNAME *headp; 639*27b03b36SApple OSS Distributions.Ed 640*27b03b36SApple OSS Distributions.Pp 641*27b03b36SApple OSS Distributions(The names 642*27b03b36SApple OSS Distributions.Li head 643*27b03b36SApple OSS Distributionsand 644*27b03b36SApple OSS Distributions.Li headp 645*27b03b36SApple OSS Distributionsare user selectable.) 646*27b03b36SApple OSS Distributions.Pp 647*27b03b36SApple OSS DistributionsThe macro 648*27b03b36SApple OSS Distributions.Nm LIST_HEAD_INITIALIZER 649*27b03b36SApple OSS Distributionsevaluates to an initializer for the list 650*27b03b36SApple OSS Distributions.Fa head . 651*27b03b36SApple OSS Distributions.Pp 652*27b03b36SApple OSS DistributionsThe macro 653*27b03b36SApple OSS Distributions.Nm LIST_EMPTY 654*27b03b36SApple OSS Distributionsevaluates to true if there are no elements in the list. 655*27b03b36SApple OSS Distributions.Pp 656*27b03b36SApple OSS DistributionsThe macro 657*27b03b36SApple OSS Distributions.Nm LIST_ENTRY 658*27b03b36SApple OSS Distributionsdeclares a structure that connects the elements in 659*27b03b36SApple OSS Distributionsthe list. 660*27b03b36SApple OSS Distributions.Pp 661*27b03b36SApple OSS DistributionsThe macro 662*27b03b36SApple OSS Distributions.Nm LIST_FIRST 663*27b03b36SApple OSS Distributionsreturns the first element in the list or NULL if the list 664*27b03b36SApple OSS Distributionsis empty. 665*27b03b36SApple OSS Distributions.Pp 666*27b03b36SApple OSS DistributionsThe macro 667*27b03b36SApple OSS Distributions.Nm LIST_FOREACH 668*27b03b36SApple OSS Distributionstraverses the list referenced by 669*27b03b36SApple OSS Distributions.Fa head 670*27b03b36SApple OSS Distributionsin the forward direction, assigning each element in turn to 671*27b03b36SApple OSS Distributions.Fa var . 672*27b03b36SApple OSS Distributions.Pp 673*27b03b36SApple OSS DistributionsThe macro 674*27b03b36SApple OSS Distributions.Nm LIST_FOREACH_SAFE 675*27b03b36SApple OSS Distributionstraverses the list referenced by 676*27b03b36SApple OSS Distributions.Fa head 677*27b03b36SApple OSS Distributionsin the forward direction, assigning each element in turn to 678*27b03b36SApple OSS Distributions.Fa var . 679*27b03b36SApple OSS DistributionsHowever, unlike 680*27b03b36SApple OSS Distributions.Fn LIST_FOREACH 681*27b03b36SApple OSS Distributionshere it is permitted to both remove 682*27b03b36SApple OSS Distributions.Fa var 683*27b03b36SApple OSS Distributionsas well as free it from within the loop safely without interfering with the 684*27b03b36SApple OSS Distributionstraversal. 685*27b03b36SApple OSS Distributions.Pp 686*27b03b36SApple OSS DistributionsThe macro 687*27b03b36SApple OSS Distributions.Nm LIST_INIT 688*27b03b36SApple OSS Distributionsinitializes the list referenced by 689*27b03b36SApple OSS Distributions.Fa head . 690*27b03b36SApple OSS Distributions.Pp 691*27b03b36SApple OSS DistributionsThe macro 692*27b03b36SApple OSS Distributions.Nm LIST_INSERT_HEAD 693*27b03b36SApple OSS Distributionsinserts the new element 694*27b03b36SApple OSS Distributions.Fa elm 695*27b03b36SApple OSS Distributionsat the head of the list. 696*27b03b36SApple OSS Distributions.Pp 697*27b03b36SApple OSS DistributionsThe macro 698*27b03b36SApple OSS Distributions.Nm LIST_INSERT_AFTER 699*27b03b36SApple OSS Distributionsinserts the new element 700*27b03b36SApple OSS Distributions.Fa elm 701*27b03b36SApple OSS Distributionsafter the element 702*27b03b36SApple OSS Distributions.Fa listelm . 703*27b03b36SApple OSS Distributions.Pp 704*27b03b36SApple OSS DistributionsThe macro 705*27b03b36SApple OSS Distributions.Nm LIST_INSERT_BEFORE 706*27b03b36SApple OSS Distributionsinserts the new element 707*27b03b36SApple OSS Distributions.Fa elm 708*27b03b36SApple OSS Distributionsbefore the element 709*27b03b36SApple OSS Distributions.Fa listelm . 710*27b03b36SApple OSS Distributions.Pp 711*27b03b36SApple OSS DistributionsThe macro 712*27b03b36SApple OSS Distributions.Nm LIST_NEXT 713*27b03b36SApple OSS Distributionsreturns the next element in the list, or NULL if this is the last. 714*27b03b36SApple OSS Distributions.Pp 715*27b03b36SApple OSS DistributionsThe macro 716*27b03b36SApple OSS Distributions.Nm LIST_REMOVE 717*27b03b36SApple OSS Distributionsremoves the element 718*27b03b36SApple OSS Distributions.Fa elm 719*27b03b36SApple OSS Distributionsfrom the list. 720*27b03b36SApple OSS Distributions.Sh LIST EXAMPLE 721*27b03b36SApple OSS Distributions.Bd -literal 722*27b03b36SApple OSS DistributionsLIST_HEAD(listhead, entry) head = 723*27b03b36SApple OSS Distributions LIST_HEAD_INITIALIZER(head); 724*27b03b36SApple OSS Distributionsstruct listhead *headp; /* List head. */ 725*27b03b36SApple OSS Distributionsstruct entry { 726*27b03b36SApple OSS Distributions ... 727*27b03b36SApple OSS Distributions LIST_ENTRY(entry) entries; /* List. */ 728*27b03b36SApple OSS Distributions ... 729*27b03b36SApple OSS Distributions} *n1, *n2, *n3, *np, *np_temp; 730*27b03b36SApple OSS Distributions 731*27b03b36SApple OSS DistributionsLIST_INIT(&head); /* Initialize the list. */ 732*27b03b36SApple OSS Distributions 733*27b03b36SApple OSS Distributionsn1 = malloc(sizeof(struct entry)); /* Insert at the head. */ 734*27b03b36SApple OSS DistributionsLIST_INSERT_HEAD(&head, n1, entries); 735*27b03b36SApple OSS Distributions 736*27b03b36SApple OSS Distributionsn2 = malloc(sizeof(struct entry)); /* Insert after. */ 737*27b03b36SApple OSS DistributionsLIST_INSERT_AFTER(n1, n2, entries); 738*27b03b36SApple OSS Distributions 739*27b03b36SApple OSS Distributionsn3 = malloc(sizeof(struct entry)); /* Insert before. */ 740*27b03b36SApple OSS DistributionsLIST_INSERT_BEFORE(n2, n3, entries); 741*27b03b36SApple OSS Distributions 742*27b03b36SApple OSS DistributionsLIST_REMOVE(n2, entries); /* Deletion. */ 743*27b03b36SApple OSS Distributionsfree(n2); 744*27b03b36SApple OSS Distributions /* Forward traversal. */ 745*27b03b36SApple OSS DistributionsLIST_FOREACH(np, &head, entries) 746*27b03b36SApple OSS Distributions np-> ... 747*27b03b36SApple OSS Distributions 748*27b03b36SApple OSS Distributions /* Safe forward traversal. */ 749*27b03b36SApple OSS DistributionsLIST_FOREACH_SAFE(np, &head, entries, np_temp) { 750*27b03b36SApple OSS Distributions np->do_stuff(); 751*27b03b36SApple OSS Distributions ... 752*27b03b36SApple OSS Distributions LIST_REMOVE(np, entries); 753*27b03b36SApple OSS Distributions free(np); 754*27b03b36SApple OSS Distributions} 755*27b03b36SApple OSS Distributions 756*27b03b36SApple OSS Distributionswhile (!LIST_EMPTY(&head)) { /* List Deletion. */ 757*27b03b36SApple OSS Distributions n1 = LIST_FIRST(&head); 758*27b03b36SApple OSS Distributions LIST_REMOVE(n1, entries); 759*27b03b36SApple OSS Distributions free(n1); 760*27b03b36SApple OSS Distributions} 761*27b03b36SApple OSS Distributions 762*27b03b36SApple OSS Distributionsn1 = LIST_FIRST(&head); /* Faster List Deletion. */ 763*27b03b36SApple OSS Distributionswhile (n1 != NULL) { 764*27b03b36SApple OSS Distributions n2 = LIST_NEXT(n1, entries); 765*27b03b36SApple OSS Distributions free(n1); 766*27b03b36SApple OSS Distributions n1 = n2; 767*27b03b36SApple OSS Distributions} 768*27b03b36SApple OSS DistributionsLIST_INIT(&head); 769*27b03b36SApple OSS Distributions.Ed 770*27b03b36SApple OSS Distributions.Sh TAIL QUEUES 771*27b03b36SApple OSS DistributionsA tail queue is headed by a structure defined by the 772*27b03b36SApple OSS Distributions.Nm TAILQ_HEAD 773*27b03b36SApple OSS Distributionsmacro. 774*27b03b36SApple OSS DistributionsThis structure contains a pair of pointers, 775*27b03b36SApple OSS Distributionsone to the first element in the tail queue and the other to 776*27b03b36SApple OSS Distributionsthe last element in the tail queue. 777*27b03b36SApple OSS DistributionsThe elements are doubly linked so that an arbitrary element can be 778*27b03b36SApple OSS Distributionsremoved without traversing the tail queue. 779*27b03b36SApple OSS DistributionsNew elements can be added to the tail queue after an existing element, 780*27b03b36SApple OSS Distributionsbefore an existing element, at the head of the tail queue, 781*27b03b36SApple OSS Distributionsor at the end of the tail queue. 782*27b03b36SApple OSS DistributionsA 783*27b03b36SApple OSS Distributions.Fa TAILQ_HEAD 784*27b03b36SApple OSS Distributionsstructure is declared as follows: 785*27b03b36SApple OSS Distributions.Bd -literal -offset indent 786*27b03b36SApple OSS DistributionsTAILQ_HEAD(HEADNAME, TYPE) head; 787*27b03b36SApple OSS Distributions.Ed 788*27b03b36SApple OSS Distributions.Pp 789*27b03b36SApple OSS Distributionswhere 790*27b03b36SApple OSS Distributions.Li HEADNAME 791*27b03b36SApple OSS Distributionsis the name of the structure to be defined, and 792*27b03b36SApple OSS Distributions.Li TYPE 793*27b03b36SApple OSS Distributionsis the type of the elements to be linked into the tail queue. 794*27b03b36SApple OSS DistributionsA pointer to the head of the tail queue can later be declared as: 795*27b03b36SApple OSS Distributions.Bd -literal -offset indent 796*27b03b36SApple OSS Distributionsstruct HEADNAME *headp; 797*27b03b36SApple OSS Distributions.Ed 798*27b03b36SApple OSS Distributions.Pp 799*27b03b36SApple OSS Distributions(The names 800*27b03b36SApple OSS Distributions.Li head 801*27b03b36SApple OSS Distributionsand 802*27b03b36SApple OSS Distributions.Li headp 803*27b03b36SApple OSS Distributionsare user selectable.) 804*27b03b36SApple OSS Distributions.Pp 805*27b03b36SApple OSS DistributionsThe macro 806*27b03b36SApple OSS Distributions.Nm TAILQ_HEAD_INITIALIZER 807*27b03b36SApple OSS Distributionsevaluates to an initializer for the tail queue 808*27b03b36SApple OSS Distributions.Fa head . 809*27b03b36SApple OSS Distributions.Pp 810*27b03b36SApple OSS DistributionsThe macro 811*27b03b36SApple OSS Distributions.Nm TAILQ_CONCAT 812*27b03b36SApple OSS Distributionsconcatenates the tail queue headed by 813*27b03b36SApple OSS Distributions.Fa head2 814*27b03b36SApple OSS Distributionsonto the end of the one headed by 815*27b03b36SApple OSS Distributions.Fa head1 816*27b03b36SApple OSS Distributionsremoving all entries from the former. 817*27b03b36SApple OSS Distributions.Pp 818*27b03b36SApple OSS DistributionsThe macro 819*27b03b36SApple OSS Distributions.Nm TAILQ_EMPTY 820*27b03b36SApple OSS Distributionsevaluates to true if there are no items on the tail queue. 821*27b03b36SApple OSS Distributions.Pp 822*27b03b36SApple OSS DistributionsThe macro 823*27b03b36SApple OSS Distributions.Nm TAILQ_ENTRY 824*27b03b36SApple OSS Distributionsdeclares a structure that connects the elements in 825*27b03b36SApple OSS Distributionsthe tail queue. 826*27b03b36SApple OSS Distributions.Pp 827*27b03b36SApple OSS DistributionsThe macro 828*27b03b36SApple OSS Distributions.Nm TAILQ_FIRST 829*27b03b36SApple OSS Distributionsreturns the first item on the tail queue or NULL if the tail queue 830*27b03b36SApple OSS Distributionsis empty. 831*27b03b36SApple OSS Distributions.Pp 832*27b03b36SApple OSS DistributionsThe macro 833*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH 834*27b03b36SApple OSS Distributionstraverses the tail queue referenced by 835*27b03b36SApple OSS Distributions.Fa head 836*27b03b36SApple OSS Distributionsin the forward direction, assigning each element in turn to 837*27b03b36SApple OSS Distributions.Fa var . 838*27b03b36SApple OSS Distributions.Fa var 839*27b03b36SApple OSS Distributionsis set to 840*27b03b36SApple OSS Distributions.Dv NULL 841*27b03b36SApple OSS Distributionsif the loop completes normally, or if there were no elements. 842*27b03b36SApple OSS Distributions.Pp 843*27b03b36SApple OSS DistributionsThe macro 844*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH_REVERSE 845*27b03b36SApple OSS Distributionstraverses the tail queue referenced by 846*27b03b36SApple OSS Distributions.Fa head 847*27b03b36SApple OSS Distributionsin the reverse direction, assigning each element in turn to 848*27b03b36SApple OSS Distributions.Fa var . 849*27b03b36SApple OSS Distributions.Pp 850*27b03b36SApple OSS DistributionsThe macros 851*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH_SAFE 852*27b03b36SApple OSS Distributionsand 853*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH_REVERSE_SAFE 854*27b03b36SApple OSS Distributionstraverse the list referenced by 855*27b03b36SApple OSS Distributions.Fa head 856*27b03b36SApple OSS Distributionsin the forward or reverse direction respectively, 857*27b03b36SApple OSS Distributionsassigning each element in turn to 858*27b03b36SApple OSS Distributions.Fa var . 859*27b03b36SApple OSS DistributionsHowever, unlike their unsafe counterparts, 860*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH 861*27b03b36SApple OSS Distributionsand 862*27b03b36SApple OSS Distributions.Nm TAILQ_FOREACH_REVERSE 863*27b03b36SApple OSS Distributionspermit to both remove 864*27b03b36SApple OSS Distributions.Fa var 865*27b03b36SApple OSS Distributionsas well as free it from within the loop safely without interfering with the 866*27b03b36SApple OSS Distributionstraversal. 867*27b03b36SApple OSS Distributions.Pp 868*27b03b36SApple OSS DistributionsThe macro 869*27b03b36SApple OSS Distributions.Nm TAILQ_INIT 870*27b03b36SApple OSS Distributionsinitializes the tail queue referenced by 871*27b03b36SApple OSS Distributions.Fa head . 872*27b03b36SApple OSS Distributions.Pp 873*27b03b36SApple OSS DistributionsThe macro 874*27b03b36SApple OSS Distributions.Nm TAILQ_INSERT_HEAD 875*27b03b36SApple OSS Distributionsinserts the new element 876*27b03b36SApple OSS Distributions.Fa elm 877*27b03b36SApple OSS Distributionsat the head of the tail queue. 878*27b03b36SApple OSS Distributions.Pp 879*27b03b36SApple OSS DistributionsThe macro 880*27b03b36SApple OSS Distributions.Nm TAILQ_INSERT_TAIL 881*27b03b36SApple OSS Distributionsinserts the new element 882*27b03b36SApple OSS Distributions.Fa elm 883*27b03b36SApple OSS Distributionsat the end of the tail queue. 884*27b03b36SApple OSS Distributions.Pp 885*27b03b36SApple OSS DistributionsThe macro 886*27b03b36SApple OSS Distributions.Nm TAILQ_INSERT_AFTER 887*27b03b36SApple OSS Distributionsinserts the new element 888*27b03b36SApple OSS Distributions.Fa elm 889*27b03b36SApple OSS Distributionsafter the element 890*27b03b36SApple OSS Distributions.Fa listelm . 891*27b03b36SApple OSS Distributions.Pp 892*27b03b36SApple OSS DistributionsThe macro 893*27b03b36SApple OSS Distributions.Nm TAILQ_INSERT_BEFORE 894*27b03b36SApple OSS Distributionsinserts the new element 895*27b03b36SApple OSS Distributions.Fa elm 896*27b03b36SApple OSS Distributionsbefore the element 897*27b03b36SApple OSS Distributions.Fa listelm . 898*27b03b36SApple OSS Distributions.Pp 899*27b03b36SApple OSS DistributionsThe macro 900*27b03b36SApple OSS Distributions.Nm TAILQ_LAST 901*27b03b36SApple OSS Distributionsreturns the last item on the tail queue. 902*27b03b36SApple OSS DistributionsIf the tail queue is empty the return value is NULL. 903*27b03b36SApple OSS Distributions.Pp 904*27b03b36SApple OSS DistributionsThe macro 905*27b03b36SApple OSS Distributions.Nm TAILQ_NEXT 906*27b03b36SApple OSS Distributionsreturns the next item on the tail queue, or NULL if this item is the last. 907*27b03b36SApple OSS Distributions.Pp 908*27b03b36SApple OSS DistributionsThe macro 909*27b03b36SApple OSS Distributions.Nm TAILQ_PREV 910*27b03b36SApple OSS Distributionsreturns the previous item on the tail queue, or NULL if this item 911*27b03b36SApple OSS Distributionsis the first. 912*27b03b36SApple OSS Distributions.Pp 913*27b03b36SApple OSS DistributionsThe macro 914*27b03b36SApple OSS Distributions.Nm TAILQ_REMOVE 915*27b03b36SApple OSS Distributionsremoves the element 916*27b03b36SApple OSS Distributions.Fa elm 917*27b03b36SApple OSS Distributionsfrom the tail queue. 918*27b03b36SApple OSS Distributions.Sh TAIL QUEUE EXAMPLE 919*27b03b36SApple OSS Distributions.Bd -literal 920*27b03b36SApple OSS DistributionsTAILQ_HEAD(tailhead, entry) head = 921*27b03b36SApple OSS Distributions TAILQ_HEAD_INITIALIZER(head); 922*27b03b36SApple OSS Distributionsstruct tailhead *headp; /* Tail queue head. */ 923*27b03b36SApple OSS Distributionsstruct entry { 924*27b03b36SApple OSS Distributions ... 925*27b03b36SApple OSS Distributions TAILQ_ENTRY(entry) entries; /* Tail queue. */ 926*27b03b36SApple OSS Distributions ... 927*27b03b36SApple OSS Distributions} *n1, *n2, *n3, *np; 928*27b03b36SApple OSS Distributions 929*27b03b36SApple OSS DistributionsTAILQ_INIT(&head); /* Initialize the queue. */ 930*27b03b36SApple OSS Distributions 931*27b03b36SApple OSS Distributionsn1 = malloc(sizeof(struct entry)); /* Insert at the head. */ 932*27b03b36SApple OSS DistributionsTAILQ_INSERT_HEAD(&head, n1, entries); 933*27b03b36SApple OSS Distributions 934*27b03b36SApple OSS Distributionsn1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ 935*27b03b36SApple OSS DistributionsTAILQ_INSERT_TAIL(&head, n1, entries); 936*27b03b36SApple OSS Distributions 937*27b03b36SApple OSS Distributionsn2 = malloc(sizeof(struct entry)); /* Insert after. */ 938*27b03b36SApple OSS DistributionsTAILQ_INSERT_AFTER(&head, n1, n2, entries); 939*27b03b36SApple OSS Distributions 940*27b03b36SApple OSS Distributionsn3 = malloc(sizeof(struct entry)); /* Insert before. */ 941*27b03b36SApple OSS DistributionsTAILQ_INSERT_BEFORE(n2, n3, entries); 942*27b03b36SApple OSS Distributions 943*27b03b36SApple OSS DistributionsTAILQ_REMOVE(&head, n2, entries); /* Deletion. */ 944*27b03b36SApple OSS Distributionsfree(n2); 945*27b03b36SApple OSS Distributions /* Forward traversal. */ 946*27b03b36SApple OSS DistributionsTAILQ_FOREACH(np, &head, entries) 947*27b03b36SApple OSS Distributions np-> ... 948*27b03b36SApple OSS Distributions /* Safe forward traversal. */ 949*27b03b36SApple OSS DistributionsTAILQ_FOREACH_SAFE(np, &head, entries, np_temp) { 950*27b03b36SApple OSS Distributions np->do_stuff(); 951*27b03b36SApple OSS Distributions ... 952*27b03b36SApple OSS Distributions TAILQ_REMOVE(&head, np, entries); 953*27b03b36SApple OSS Distributions free(np); 954*27b03b36SApple OSS Distributions} 955*27b03b36SApple OSS Distributions /* Reverse traversal. */ 956*27b03b36SApple OSS DistributionsTAILQ_FOREACH_REVERSE(np, &head, tailhead, entries) 957*27b03b36SApple OSS Distributions np-> ... 958*27b03b36SApple OSS Distributions /* TailQ Deletion. */ 959*27b03b36SApple OSS Distributionswhile (!TAILQ_EMPTY(&head)) { 960*27b03b36SApple OSS Distributions n1 = TAILQ_FIRST(&head); 961*27b03b36SApple OSS Distributions TAILQ_REMOVE(&head, n1, entries); 962*27b03b36SApple OSS Distributions free(n1); 963*27b03b36SApple OSS Distributions} 964*27b03b36SApple OSS Distributions /* Faster TailQ Deletion. */ 965*27b03b36SApple OSS Distributionsn1 = TAILQ_FIRST(&head); 966*27b03b36SApple OSS Distributionswhile (n1 != NULL) { 967*27b03b36SApple OSS Distributions n2 = TAILQ_NEXT(n1, entries); 968*27b03b36SApple OSS Distributions free(n1); 969*27b03b36SApple OSS Distributions n1 = n2; 970*27b03b36SApple OSS Distributions} 971*27b03b36SApple OSS DistributionsTAILQ_INIT(&head); 972*27b03b36SApple OSS Distributions.Ed 973*27b03b36SApple OSS Distributions.Sh HISTORY 974*27b03b36SApple OSS DistributionsThe 975*27b03b36SApple OSS Distributions.Nm queue 976*27b03b36SApple OSS Distributionsfunctions first appeared in 977*27b03b36SApple OSS Distributions.Bx 4.4 . 978