1afe61c15SRodney W. Grimes.\" Copyright (c) 1993 2afe61c15SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 3afe61c15SRodney W. Grimes.\" 4afe61c15SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 5afe61c15SRodney W. Grimes.\" modification, are permitted provided that the following conditions 6afe61c15SRodney W. Grimes.\" are met: 7afe61c15SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 8afe61c15SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 9afe61c15SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 10afe61c15SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 11afe61c15SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 12afe61c15SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 13afe61c15SRodney W. Grimes.\" must display the following acknowledgement: 14afe61c15SRodney W. Grimes.\" This product includes software developed by the University of 15afe61c15SRodney W. Grimes.\" California, Berkeley and its contributors. 16afe61c15SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 17afe61c15SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 18afe61c15SRodney W. Grimes.\" without specific prior written permission. 19afe61c15SRodney W. Grimes.\" 20afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23afe61c15SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30afe61c15SRodney W. Grimes.\" SUCH DAMAGE. 31afe61c15SRodney W. Grimes.\" 32afe61c15SRodney W. Grimes.\" @(#)queue.3 8.2 (Berkeley) 1/24/94 337f3dea24SPeter Wemm.\" $FreeBSD$ 34afe61c15SRodney W. Grimes.\" 3581ae4b8dSRuslan Ermilov.Dd March 24, 2006 36afe61c15SRodney W. Grimes.Dt QUEUE 3 373d45e180SRuslan Ermilov.Os 38afe61c15SRodney W. Grimes.Sh NAME 39aea88892SPoul-Henning Kamp.Nm SLIST_EMPTY , 404a775e8fSJustin T. Gibbs.Nm SLIST_ENTRY , 41aea88892SPoul-Henning Kamp.Nm SLIST_FIRST , 4279ea9bc4SAlexey Zelkin.Nm SLIST_FOREACH , 432724bce2SAlexander Kabaev.Nm SLIST_FOREACH_SAFE , 444a775e8fSJustin T. Gibbs.Nm SLIST_HEAD , 4503763fe0SJake Burkholder.Nm SLIST_HEAD_INITIALIZER , 464a775e8fSJustin T. Gibbs.Nm SLIST_INIT , 474a775e8fSJustin T. Gibbs.Nm SLIST_INSERT_AFTER , 484a775e8fSJustin T. Gibbs.Nm SLIST_INSERT_HEAD , 49aea88892SPoul-Henning Kamp.Nm SLIST_NEXT , 503d98b75bSEd Schouten.Nm SLIST_REMOVE_AFTER , 514a775e8fSJustin T. Gibbs.Nm SLIST_REMOVE_HEAD , 524a775e8fSJustin T. Gibbs.Nm SLIST_REMOVE , 53d57e28adSThomas Moestl.Nm STAILQ_CONCAT , 5479ea9bc4SAlexey Zelkin.Nm STAILQ_EMPTY , 554a775e8fSJustin T. Gibbs.Nm STAILQ_ENTRY , 5679ea9bc4SAlexey Zelkin.Nm STAILQ_FIRST , 5779ea9bc4SAlexey Zelkin.Nm STAILQ_FOREACH , 582724bce2SAlexander Kabaev.Nm STAILQ_FOREACH_SAFE , 594a775e8fSJustin T. Gibbs.Nm STAILQ_HEAD , 6003763fe0SJake Burkholder.Nm STAILQ_HEAD_INITIALIZER , 614a775e8fSJustin T. Gibbs.Nm STAILQ_INIT , 624a775e8fSJustin T. Gibbs.Nm STAILQ_INSERT_AFTER , 634a775e8fSJustin T. Gibbs.Nm STAILQ_INSERT_HEAD , 644a775e8fSJustin T. Gibbs.Nm STAILQ_INSERT_TAIL , 6579ea9bc4SAlexey Zelkin.Nm STAILQ_LAST , 6679ea9bc4SAlexey Zelkin.Nm STAILQ_NEXT , 673d98b75bSEd Schouten.Nm STAILQ_REMOVE_AFTER , 684a775e8fSJustin T. Gibbs.Nm STAILQ_REMOVE_HEAD , 694a775e8fSJustin T. Gibbs.Nm STAILQ_REMOVE , 7079ea9bc4SAlexey Zelkin.Nm LIST_EMPTY , 71afe61c15SRodney W. Grimes.Nm LIST_ENTRY , 7279ea9bc4SAlexey Zelkin.Nm LIST_FIRST , 7379ea9bc4SAlexey Zelkin.Nm LIST_FOREACH , 744250a68eSBosko Milekic.Nm LIST_FOREACH_SAFE , 75afe61c15SRodney W. Grimes.Nm LIST_HEAD , 7603763fe0SJake Burkholder.Nm LIST_HEAD_INITIALIZER , 77afe61c15SRodney W. Grimes.Nm LIST_INIT , 78afe61c15SRodney W. Grimes.Nm LIST_INSERT_AFTER , 797658b0a2SJustin T. Gibbs.Nm LIST_INSERT_BEFORE , 80afe61c15SRodney W. Grimes.Nm LIST_INSERT_HEAD , 8179ea9bc4SAlexey Zelkin.Nm LIST_NEXT , 82afe61c15SRodney W. Grimes.Nm LIST_REMOVE , 83d57e28adSThomas Moestl.Nm TAILQ_CONCAT , 84c5c15c16SPoul-Henning Kamp.Nm TAILQ_EMPTY , 85afe61c15SRodney W. Grimes.Nm TAILQ_ENTRY , 86c5c15c16SPoul-Henning Kamp.Nm TAILQ_FIRST , 8779ea9bc4SAlexey Zelkin.Nm TAILQ_FOREACH , 882724bce2SAlexander Kabaev.Nm TAILQ_FOREACH_SAFE , 896c1d0fbfSArchie Cobbs.Nm TAILQ_FOREACH_REVERSE , 902724bce2SAlexander Kabaev.Nm TAILQ_FOREACH_REVERSE_SAFE , 91afe61c15SRodney W. Grimes.Nm TAILQ_HEAD , 9203763fe0SJake Burkholder.Nm TAILQ_HEAD_INITIALIZER , 93afe61c15SRodney W. Grimes.Nm TAILQ_INIT , 94afe61c15SRodney W. Grimes.Nm TAILQ_INSERT_AFTER , 957658b0a2SJustin T. Gibbs.Nm TAILQ_INSERT_BEFORE , 96afe61c15SRodney W. Grimes.Nm TAILQ_INSERT_HEAD , 97afe61c15SRodney W. Grimes.Nm TAILQ_INSERT_TAIL , 98c5c15c16SPoul-Henning Kamp.Nm TAILQ_LAST , 99c5c15c16SPoul-Henning Kamp.Nm TAILQ_NEXT , 10079ea9bc4SAlexey Zelkin.Nm TAILQ_PREV , 101b4660c37SBen Smithurst.Nm TAILQ_REMOVE 1024a775e8fSJustin T. Gibbs.Nd implementations of singly-linked lists, singly-linked tail queues, 10324b85d18SPoul-Henning Kamplists and tail queues 104afe61c15SRodney W. Grimes.Sh SYNOPSIS 10532eef9aeSRuslan Ermilov.In sys/queue.h 1068f20a914SMike Pritchard.\" 107aea88892SPoul-Henning Kamp.Fn SLIST_EMPTY "SLIST_HEAD *head" 1084a775e8fSJustin T. Gibbs.Fn SLIST_ENTRY "TYPE" 109aea88892SPoul-Henning Kamp.Fn SLIST_FIRST "SLIST_HEAD *head" 11079ea9bc4SAlexey Zelkin.Fn SLIST_FOREACH "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" 1112724bce2SAlexander Kabaev.Fn SLIST_FOREACH_SAFE "TYPE *var" "SLIST_HEAD *head" "SLIST_ENTRY NAME" "TYPE *temp_var" 1124a775e8fSJustin T. Gibbs.Fn SLIST_HEAD "HEADNAME" "TYPE" 11303763fe0SJake Burkholder.Fn SLIST_HEAD_INITIALIZER "SLIST_HEAD head" 1144a775e8fSJustin T. Gibbs.Fn SLIST_INIT "SLIST_HEAD *head" 1154a775e8fSJustin T. Gibbs.Fn SLIST_INSERT_AFTER "TYPE *listelm" "TYPE *elm" "SLIST_ENTRY NAME" 1164a775e8fSJustin T. Gibbs.Fn SLIST_INSERT_HEAD "SLIST_HEAD *head" "TYPE *elm" "SLIST_ENTRY NAME" 117aea88892SPoul-Henning Kamp.Fn SLIST_NEXT "TYPE *elm" "SLIST_ENTRY NAME" 1183d98b75bSEd Schouten.Fn SLIST_REMOVE_AFTER "TYPE *elm" "SLIST_ENTRY NAME" 1194a775e8fSJustin T. Gibbs.Fn SLIST_REMOVE_HEAD "SLIST_HEAD *head" "SLIST_ENTRY NAME" 1204a775e8fSJustin T. Gibbs.Fn SLIST_REMOVE "SLIST_HEAD *head" "TYPE *elm" "TYPE" "SLIST_ENTRY NAME" 1218f20a914SMike Pritchard.\" 122d57e28adSThomas Moestl.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" 12379ea9bc4SAlexey Zelkin.Fn STAILQ_EMPTY "STAILQ_HEAD *head" 1244a775e8fSJustin T. Gibbs.Fn STAILQ_ENTRY "TYPE" 12579ea9bc4SAlexey Zelkin.Fn STAILQ_FIRST "STAILQ_HEAD *head" 12679ea9bc4SAlexey Zelkin.Fn STAILQ_FOREACH "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" 1272724bce2SAlexander Kabaev.Fn STAILQ_FOREACH_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var" 1284a775e8fSJustin T. Gibbs.Fn STAILQ_HEAD "HEADNAME" "TYPE" 12903763fe0SJake Burkholder.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head" 1304a775e8fSJustin T. Gibbs.Fn STAILQ_INIT "STAILQ_HEAD *head" 1314a775e8fSJustin T. Gibbs.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "STAILQ_ENTRY NAME" 1324a775e8fSJustin T. Gibbs.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME" 1334a775e8fSJustin T. Gibbs.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME" 134f36b6e4bSMaxim Sobolev.Fn STAILQ_LAST "STAILQ_HEAD *head" "TYPE" "STAILQ_ENTRY NAME" 13579ea9bc4SAlexey Zelkin.Fn STAILQ_NEXT "TYPE *elm" "STAILQ_ENTRY NAME" 1363d98b75bSEd Schouten.Fn STAILQ_REMOVE_AFTER "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME" 13702a98699SBruce Evans.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" 1384a775e8fSJustin T. Gibbs.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "TYPE *elm" "TYPE" "STAILQ_ENTRY NAME" 1398f20a914SMike Pritchard.\" 14079ea9bc4SAlexey Zelkin.Fn LIST_EMPTY "LIST_HEAD *head" 141afe61c15SRodney W. Grimes.Fn LIST_ENTRY "TYPE" 14279ea9bc4SAlexey Zelkin.Fn LIST_FIRST "LIST_HEAD *head" 14379ea9bc4SAlexey Zelkin.Fn LIST_FOREACH "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" 1444250a68eSBosko Milekic.Fn LIST_FOREACH_SAFE "TYPE *var" "LIST_HEAD *head" "LIST_ENTRY NAME" "TYPE *temp_var" 145afe61c15SRodney W. Grimes.Fn LIST_HEAD "HEADNAME" "TYPE" 14603763fe0SJake Burkholder.Fn LIST_HEAD_INITIALIZER "LIST_HEAD head" 147afe61c15SRodney W. Grimes.Fn LIST_INIT "LIST_HEAD *head" 1484a775e8fSJustin T. Gibbs.Fn LIST_INSERT_AFTER "TYPE *listelm" "TYPE *elm" "LIST_ENTRY NAME" 1494a775e8fSJustin T. Gibbs.Fn LIST_INSERT_BEFORE "TYPE *listelm" "TYPE *elm" "LIST_ENTRY NAME" 150afe61c15SRodney W. Grimes.Fn LIST_INSERT_HEAD "LIST_HEAD *head" "TYPE *elm" "LIST_ENTRY NAME" 15179ea9bc4SAlexey Zelkin.Fn LIST_NEXT "TYPE *elm" "LIST_ENTRY NAME" 152afe61c15SRodney W. Grimes.Fn LIST_REMOVE "TYPE *elm" "LIST_ENTRY NAME" 1538f20a914SMike Pritchard.\" 154d57e28adSThomas Moestl.Fn TAILQ_CONCAT "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TAILQ_ENTRY NAME" 155c5c15c16SPoul-Henning Kamp.Fn TAILQ_EMPTY "TAILQ_HEAD *head" 156afe61c15SRodney W. Grimes.Fn TAILQ_ENTRY "TYPE" 157c5c15c16SPoul-Henning Kamp.Fn TAILQ_FIRST "TAILQ_HEAD *head" 15879ea9bc4SAlexey Zelkin.Fn TAILQ_FOREACH "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" 1592724bce2SAlexander Kabaev.Fn TAILQ_FOREACH_SAFE "TYPE *var" "TAILQ_HEAD *head" "TAILQ_ENTRY NAME" "TYPE *temp_var" 1606c1d0fbfSArchie Cobbs.Fn TAILQ_FOREACH_REVERSE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" 1612724bce2SAlexander Kabaev.Fn TAILQ_FOREACH_REVERSE_SAFE "TYPE *var" "TAILQ_HEAD *head" "HEADNAME" "TAILQ_ENTRY NAME" "TYPE *temp_var" 162afe61c15SRodney W. Grimes.Fn TAILQ_HEAD "HEADNAME" "TYPE" 16303763fe0SJake Burkholder.Fn TAILQ_HEAD_INITIALIZER "TAILQ_HEAD head" 164afe61c15SRodney W. Grimes.Fn TAILQ_INIT "TAILQ_HEAD *head" 165afe61c15SRodney W. Grimes.Fn TAILQ_INSERT_AFTER "TAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "TAILQ_ENTRY NAME" 1663652ff55SJustin T. Gibbs.Fn TAILQ_INSERT_BEFORE "TYPE *listelm" "TYPE *elm" "TAILQ_ENTRY NAME" 167afe61c15SRodney W. Grimes.Fn TAILQ_INSERT_HEAD "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME" 168afe61c15SRodney W. Grimes.Fn TAILQ_INSERT_TAIL "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME" 16979ea9bc4SAlexey Zelkin.Fn TAILQ_LAST "TAILQ_HEAD *head" "HEADNAME" 170c5c15c16SPoul-Henning Kamp.Fn TAILQ_NEXT "TYPE *elm" "TAILQ_ENTRY NAME" 17179ea9bc4SAlexey Zelkin.Fn TAILQ_PREV "TYPE *elm" "HEADNAME" "TAILQ_ENTRY NAME" 172afe61c15SRodney W. Grimes.Fn TAILQ_REMOVE "TAILQ_HEAD *head" "TYPE *elm" "TAILQ_ENTRY NAME" 1738f20a914SMike Pritchard.\" 174afe61c15SRodney W. Grimes.Sh DESCRIPTION 175b86388c1SDima DorfmanThese macros define and operate on four types of data structures: 176b86388c1SDima Dorfmansingly-linked lists, singly-linked tail queues, lists, and tail queues. 177b86388c1SDima DorfmanAll four structures support the following functionality: 178afe61c15SRodney W. Grimes.Bl -enum -compact -offset indent 179afe61c15SRodney W. Grimes.It 180afe61c15SRodney W. GrimesInsertion of a new entry at the head of the list. 181afe61c15SRodney W. Grimes.It 182afe61c15SRodney W. GrimesInsertion of a new entry after any element in the list. 183afe61c15SRodney W. Grimes.It 1844a775e8fSJustin T. GibbsO(1) removal of an entry from the head of the list. 1857658b0a2SJustin T. Gibbs.It 186afe61c15SRodney W. GrimesForward traversal through the list. 187afe61c15SRodney W. Grimes.El 188afe61c15SRodney W. Grimes.Pp 189ed741d4eSDavid E. O'BrienO(n) removal of any entry in the list. 190d5fd66e1SEd MasteSingly-linked lists are the simplest of the four data structures 1914a775e8fSJustin T. Gibbsand support only the above functionality. 1924a775e8fSJustin T. GibbsSingly-linked lists are ideal for applications with large datasets 1934a775e8fSJustin T. Gibbsand few or no removals, 1944a775e8fSJustin T. Gibbsor for implementing a LIFO queue. 195ed741d4eSDavid E. O'BrienSingly-linked lists add the following functionality: 196ed741d4eSDavid E. O'Brien.Bl -enum -compact -offset indent 197ed741d4eSDavid E. O'Brien.It 198ed741d4eSDavid E. O'BrienO(n) removal of any entry in the list. 199ed741d4eSDavid E. O'Brien.El 2004a775e8fSJustin T. Gibbs.Pp 2014a775e8fSJustin T. GibbsSingly-linked tail queues add the following functionality: 2024a775e8fSJustin T. Gibbs.Bl -enum -compact -offset indent 2034a775e8fSJustin T. Gibbs.It 2044a775e8fSJustin T. GibbsEntries can be added at the end of a list. 205d57e28adSThomas Moestl.It 206ed741d4eSDavid E. O'BrienO(n) removal of any entry in the list. 207ed741d4eSDavid E. O'Brien.It 208d57e28adSThomas MoestlThey may be concatenated. 2094a775e8fSJustin T. Gibbs.El 2104a775e8fSJustin T. GibbsHowever: 2114a775e8fSJustin T. Gibbs.Bl -enum -compact -offset indent 2124a775e8fSJustin T. Gibbs.It 2134a775e8fSJustin T. GibbsAll list insertions must specify the head of the list. 2144a775e8fSJustin T. Gibbs.It 2154a775e8fSJustin T. GibbsEach head entry requires two pointers rather than one. 2164a775e8fSJustin T. Gibbs.It 2174a775e8fSJustin T. GibbsCode size is about 15% greater and operations run about 20% slower 2184a775e8fSJustin T. Gibbsthan singly-linked lists. 2194a775e8fSJustin T. Gibbs.El 2204a775e8fSJustin T. Gibbs.Pp 2214a775e8fSJustin T. GibbsSingly-linked tailqs are ideal for applications with large datasets and 2224a775e8fSJustin T. Gibbsfew or no removals, 2234a775e8fSJustin T. Gibbsor for implementing a FIFO queue. 2244a775e8fSJustin T. Gibbs.Pp 225b86388c1SDima DorfmanAll doubly linked types of data structures (lists and tail queues) 226b86388c1SDima Dorfmanadditionally allow: 2274a775e8fSJustin T. Gibbs.Bl -enum -compact -offset indent 2284a775e8fSJustin T. Gibbs.It 2294a775e8fSJustin T. GibbsInsertion of a new entry before any element in the list. 2304a775e8fSJustin T. Gibbs.It 2314a775e8fSJustin T. GibbsO(1) removal of any entry in the list. 2324a775e8fSJustin T. Gibbs.El 2334a775e8fSJustin T. GibbsHowever: 2344a775e8fSJustin T. Gibbs.Bl -enum -compact -offset indent 2354a775e8fSJustin T. Gibbs.It 236ad035dafSChristian BruefferEach element requires two pointers rather than one. 2374a775e8fSJustin T. Gibbs.It 2384a775e8fSJustin T. GibbsCode size and execution time of operations (except for removal) is about 2394a775e8fSJustin T. Gibbstwice that of the singly-linked data-structures. 2404a775e8fSJustin T. Gibbs.El 2414a775e8fSJustin T. Gibbs.Pp 2424a775e8fSJustin T. GibbsLinked lists are the simplest of the doubly linked data structures and support 2434a775e8fSJustin T. Gibbsonly the above functionality over singly-linked lists. 244afe61c15SRodney W. Grimes.Pp 245afe61c15SRodney W. GrimesTail queues add the following functionality: 246afe61c15SRodney W. Grimes.Bl -enum -compact -offset indent 247afe61c15SRodney W. Grimes.It 248afe61c15SRodney W. GrimesEntries can be added at the end of a list. 2496c1d0fbfSArchie Cobbs.It 2506c1d0fbfSArchie CobbsThey may be traversed backwards, from tail to head. 251d57e28adSThomas Moestl.It 252d57e28adSThomas MoestlThey may be concatenated. 253afe61c15SRodney W. Grimes.El 254afe61c15SRodney W. GrimesHowever: 255afe61c15SRodney W. Grimes.Bl -enum -compact -offset indent 256afe61c15SRodney W. Grimes.It 257afe61c15SRodney W. GrimesAll list insertions and removals must specify the head of the list. 258afe61c15SRodney W. Grimes.It 259afe61c15SRodney W. GrimesEach head entry requires two pointers rather than one. 260afe61c15SRodney W. Grimes.It 261afe61c15SRodney W. GrimesCode size is about 15% greater and operations run about 20% slower 2624a775e8fSJustin T. Gibbsthan singly-linked lists. 263afe61c15SRodney W. Grimes.El 264afe61c15SRodney W. Grimes.Pp 265afe61c15SRodney W. GrimesIn the macro definitions, 266afe61c15SRodney W. Grimes.Fa TYPE 267afe61c15SRodney W. Grimesis the name of a user defined structure, 268afe61c15SRodney W. Grimesthat must contain a field of type 2694a775e8fSJustin T. Gibbs.Li SLIST_ENTRY , 2704a775e8fSJustin T. Gibbs.Li STAILQ_ENTRY , 271afe61c15SRodney W. Grimes.Li LIST_ENTRY , 272afe61c15SRodney W. Grimesor 27324b85d18SPoul-Henning Kamp.Li TAILQ_ENTRY , 274afe61c15SRodney W. Grimesnamed 275afe61c15SRodney W. Grimes.Fa NAME . 276afe61c15SRodney W. GrimesThe argument 277afe61c15SRodney W. Grimes.Fa HEADNAME 278afe61c15SRodney W. Grimesis the name of a user defined structure that must be declared 279afe61c15SRodney W. Grimesusing the macros 2804a775e8fSJustin T. Gibbs.Li SLIST_HEAD , 2814a775e8fSJustin T. Gibbs.Li STAILQ_HEAD , 282afe61c15SRodney W. Grimes.Li LIST_HEAD , 283afe61c15SRodney W. Grimesor 28424b85d18SPoul-Henning Kamp.Li TAILQ_HEAD . 285afe61c15SRodney W. GrimesSee the examples below for further explanation of how these 286afe61c15SRodney W. Grimesmacros are used. 2874a775e8fSJustin T. Gibbs.Sh SINGLY-LINKED LISTS 2884a775e8fSJustin T. GibbsA singly-linked list is headed by a structure defined by the 2894a775e8fSJustin T. Gibbs.Nm SLIST_HEAD 2904a775e8fSJustin T. Gibbsmacro. 2914a775e8fSJustin T. GibbsThis structure contains a single pointer to the first element 2924a775e8fSJustin T. Gibbson the list. 2934a775e8fSJustin T. GibbsThe elements are singly linked for minimum space and pointer manipulation 2944a775e8fSJustin T. Gibbsoverhead at the expense of O(n) removal for arbitrary elements. 2954a775e8fSJustin T. GibbsNew elements can be added to the list after an existing element or 2964a775e8fSJustin T. Gibbsat the head of the list. 2974a775e8fSJustin T. GibbsAn 2984a775e8fSJustin T. Gibbs.Fa SLIST_HEAD 2994a775e8fSJustin T. Gibbsstructure is declared as follows: 3004a775e8fSJustin T. Gibbs.Bd -literal -offset indent 3014a775e8fSJustin T. GibbsSLIST_HEAD(HEADNAME, TYPE) head; 3024a775e8fSJustin T. Gibbs.Ed 3038f20a914SMike Pritchard.Pp 3044a775e8fSJustin T. Gibbswhere 3054a775e8fSJustin T. Gibbs.Fa HEADNAME 3064a775e8fSJustin T. Gibbsis the name of the structure to be defined, and 3074a775e8fSJustin T. Gibbs.Fa TYPE 3084a775e8fSJustin T. Gibbsis the type of the elements to be linked into the list. 3094a775e8fSJustin T. GibbsA pointer to the head of the list can later be declared as: 3104a775e8fSJustin T. Gibbs.Bd -literal -offset indent 3114a775e8fSJustin T. Gibbsstruct HEADNAME *headp; 3124a775e8fSJustin T. Gibbs.Ed 3138f20a914SMike Pritchard.Pp 3144a775e8fSJustin T. Gibbs(The names 3154a775e8fSJustin T. Gibbs.Li head 3164a775e8fSJustin T. Gibbsand 3174a775e8fSJustin T. Gibbs.Li headp 3184a775e8fSJustin T. Gibbsare user selectable.) 3194a775e8fSJustin T. Gibbs.Pp 3204a775e8fSJustin T. GibbsThe macro 32103763fe0SJake Burkholder.Nm SLIST_HEAD_INITIALIZER 32203763fe0SJake Burkholderevaluates to an initializer for the list 32303763fe0SJake Burkholder.Fa head . 32403763fe0SJake Burkholder.Pp 32503763fe0SJake BurkholderThe macro 32679ea9bc4SAlexey Zelkin.Nm SLIST_EMPTY 32779ea9bc4SAlexey Zelkinevaluates to true if there are no elements in the list. 32879ea9bc4SAlexey Zelkin.Pp 32979ea9bc4SAlexey ZelkinThe macro 3304a775e8fSJustin T. Gibbs.Nm SLIST_ENTRY 3314a775e8fSJustin T. Gibbsdeclares a structure that connects the elements in 3324a775e8fSJustin T. Gibbsthe list. 3334a775e8fSJustin T. Gibbs.Pp 3344a775e8fSJustin T. GibbsThe macro 33579ea9bc4SAlexey Zelkin.Nm SLIST_FIRST 33679ea9bc4SAlexey Zelkinreturns the first element in the list or NULL if the list is empty. 33779ea9bc4SAlexey Zelkin.Pp 33879ea9bc4SAlexey ZelkinThe macro 33979ea9bc4SAlexey Zelkin.Nm SLIST_FOREACH 34079ea9bc4SAlexey Zelkintraverses the list referenced by 34179ea9bc4SAlexey Zelkin.Fa head 34279ea9bc4SAlexey Zelkinin the forward direction, assigning each element in 34379ea9bc4SAlexey Zelkinturn to 34479ea9bc4SAlexey Zelkin.Fa var . 34579ea9bc4SAlexey Zelkin.Pp 34679ea9bc4SAlexey ZelkinThe macro 3472724bce2SAlexander Kabaev.Nm SLIST_FOREACH_SAFE 3482724bce2SAlexander Kabaevtraverses the list referenced by 3492724bce2SAlexander Kabaev.Fa head 3502724bce2SAlexander Kabaevin the forward direction, assigning each element in 3512724bce2SAlexander Kabaevturn to 3522724bce2SAlexander Kabaev.Fa var . 3532724bce2SAlexander KabaevHowever, unlike 3542724bce2SAlexander Kabaev.Fn SLIST_FOREACH 3552724bce2SAlexander Kabaevhere it is permitted to both remove 3562724bce2SAlexander Kabaev.Fa var 3572724bce2SAlexander Kabaevas well as free it from within the loop safely without interfering with the 3582724bce2SAlexander Kabaevtraversal. 3592724bce2SAlexander Kabaev.Pp 3602724bce2SAlexander KabaevThe macro 3614a775e8fSJustin T. Gibbs.Nm SLIST_INIT 3624a775e8fSJustin T. Gibbsinitializes the list referenced by 3634a775e8fSJustin T. Gibbs.Fa head . 3644a775e8fSJustin T. Gibbs.Pp 3654a775e8fSJustin T. GibbsThe macro 3664a775e8fSJustin T. Gibbs.Nm SLIST_INSERT_HEAD 3674a775e8fSJustin T. Gibbsinserts the new element 3684a775e8fSJustin T. Gibbs.Fa elm 3694a775e8fSJustin T. Gibbsat the head of the list. 3704a775e8fSJustin T. Gibbs.Pp 3714a775e8fSJustin T. GibbsThe macro 3724a775e8fSJustin T. Gibbs.Nm SLIST_INSERT_AFTER 3734a775e8fSJustin T. Gibbsinserts the new element 3744a775e8fSJustin T. Gibbs.Fa elm 3754a775e8fSJustin T. Gibbsafter the element 3764a775e8fSJustin T. Gibbs.Fa listelm . 3774a775e8fSJustin T. Gibbs.Pp 3784a775e8fSJustin T. GibbsThe macro 37979ea9bc4SAlexey Zelkin.Nm SLIST_NEXT 38079ea9bc4SAlexey Zelkinreturns the next element in the list. 38179ea9bc4SAlexey Zelkin.Pp 38279ea9bc4SAlexey ZelkinThe macro 3833d98b75bSEd Schouten.Nm SLIST_REMOVE_AFTER 3843d98b75bSEd Schoutenremoves the element after 3853d98b75bSEd Schouten.Fa elm 3863d98b75bSEd Schoutenfrom the list. Unlike 3873d98b75bSEd Schouten.Fa SLIST_REMOVE , 3883d98b75bSEd Schoutenthis macro does not traverse the entire list. 3893d98b75bSEd Schouten.Pp 3903d98b75bSEd SchoutenThe macro 3914a775e8fSJustin T. Gibbs.Nm SLIST_REMOVE_HEAD 3924a775e8fSJustin T. Gibbsremoves the element 3934a775e8fSJustin T. Gibbs.Fa elm 3944a775e8fSJustin T. Gibbsfrom the head of the list. 3954a775e8fSJustin T. GibbsFor optimum efficiency, 3964a775e8fSJustin T. Gibbselements being removed from the head of the list should explicitly use 3974a775e8fSJustin T. Gibbsthis macro instead of the generic 3984a775e8fSJustin T. Gibbs.Fa SLIST_REMOVE 3994a775e8fSJustin T. Gibbsmacro. 4004a775e8fSJustin T. Gibbs.Pp 4014a775e8fSJustin T. GibbsThe macro 4024a775e8fSJustin T. Gibbs.Nm SLIST_REMOVE 4034a775e8fSJustin T. Gibbsremoves the element 4044a775e8fSJustin T. Gibbs.Fa elm 4054a775e8fSJustin T. Gibbsfrom the list. 4064a775e8fSJustin T. Gibbs.Sh SINGLY-LINKED LIST EXAMPLE 4074a775e8fSJustin T. Gibbs.Bd -literal 40803763fe0SJake BurkholderSLIST_HEAD(slisthead, entry) head = 40903763fe0SJake Burkholder SLIST_HEAD_INITIALIZER(head); 4104a775e8fSJustin T. Gibbsstruct slisthead *headp; /* Singly-linked List head. */ 4114a775e8fSJustin T. Gibbsstruct entry { 4124a775e8fSJustin T. Gibbs ... 4134a775e8fSJustin T. Gibbs SLIST_ENTRY(entry) entries; /* Singly-linked List. */ 4144a775e8fSJustin T. Gibbs ... 4154a775e8fSJustin T. Gibbs} *n1, *n2, *n3, *np; 4164a775e8fSJustin T. Gibbs 4174a775e8fSJustin T. GibbsSLIST_INIT(&head); /* Initialize the list. */ 4184a775e8fSJustin T. Gibbs 4194a775e8fSJustin T. Gibbsn1 = malloc(sizeof(struct entry)); /* Insert at the head. */ 4204a775e8fSJustin T. GibbsSLIST_INSERT_HEAD(&head, n1, entries); 4214a775e8fSJustin T. Gibbs 4224a775e8fSJustin T. Gibbsn2 = malloc(sizeof(struct entry)); /* Insert after. */ 4234a775e8fSJustin T. GibbsSLIST_INSERT_AFTER(n1, n2, entries); 4244a775e8fSJustin T. Gibbs 4254a775e8fSJustin T. GibbsSLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */ 4264a775e8fSJustin T. Gibbsfree(n2); 4274a775e8fSJustin T. Gibbs 42879ea9bc4SAlexey Zelkinn3 = SLIST_FIRST(&head); 42903763fe0SJake BurkholderSLIST_REMOVE_HEAD(&head, entries); /* Deletion from the head. */ 4304a775e8fSJustin T. Gibbsfree(n3); 4314a775e8fSJustin T. Gibbs /* Forward traversal. */ 43279ea9bc4SAlexey ZelkinSLIST_FOREACH(np, &head, entries) 4334a775e8fSJustin T. Gibbs np-> ... 4342724bce2SAlexander Kabaev /* Safe forward traversal. */ 4352724bce2SAlexander KabaevSLIST_FOREACH_SAFE(np, &head, entries, np_temp) { 4362724bce2SAlexander Kabaev np->do_stuff(); 4372724bce2SAlexander Kabaev ... 4382724bce2SAlexander Kabaev SLIST_REMOVE(&head, np, entry, entries); 4392724bce2SAlexander Kabaev free(np); 4402724bce2SAlexander Kabaev} 4414a775e8fSJustin T. Gibbs 44279ea9bc4SAlexey Zelkinwhile (!SLIST_EMPTY(&head)) { /* List Deletion. */ 44379ea9bc4SAlexey Zelkin n1 = SLIST_FIRST(&head); 4444a775e8fSJustin T. Gibbs SLIST_REMOVE_HEAD(&head, entries); 4454a775e8fSJustin T. Gibbs free(n1); 4464a775e8fSJustin T. Gibbs} 4474a775e8fSJustin T. Gibbs.Ed 4484a775e8fSJustin T. Gibbs.Sh SINGLY-LINKED TAIL QUEUES 4494a775e8fSJustin T. GibbsA singly-linked tail queue is headed by a structure defined by the 4504a775e8fSJustin T. Gibbs.Nm STAILQ_HEAD 4514a775e8fSJustin T. Gibbsmacro. 4524a775e8fSJustin T. GibbsThis structure contains a pair of pointers, 4534a775e8fSJustin T. Gibbsone to the first element in the tail queue and the other to 4544a775e8fSJustin T. Gibbsthe last element in the tail queue. 4554a775e8fSJustin T. GibbsThe elements are singly linked for minimum space and pointer 4564a775e8fSJustin T. Gibbsmanipulation overhead at the expense of O(n) removal for arbitrary 4574a775e8fSJustin T. Gibbselements. 4584a775e8fSJustin T. GibbsNew elements can be added to the tail queue after an existing element, 4594a775e8fSJustin T. Gibbsat the head of the tail queue, or at the end of the tail queue. 4604a775e8fSJustin T. GibbsA 4614a775e8fSJustin T. Gibbs.Fa STAILQ_HEAD 4624a775e8fSJustin T. Gibbsstructure is declared as follows: 4634a775e8fSJustin T. Gibbs.Bd -literal -offset indent 4644a775e8fSJustin T. GibbsSTAILQ_HEAD(HEADNAME, TYPE) head; 4654a775e8fSJustin T. Gibbs.Ed 4668f20a914SMike Pritchard.Pp 4674a775e8fSJustin T. Gibbswhere 4684a775e8fSJustin T. Gibbs.Li HEADNAME 4694a775e8fSJustin T. Gibbsis the name of the structure to be defined, and 4704a775e8fSJustin T. Gibbs.Li TYPE 4714a775e8fSJustin T. Gibbsis the type of the elements to be linked into the tail queue. 4724a775e8fSJustin T. GibbsA pointer to the head of the tail queue can later be declared as: 4734a775e8fSJustin T. Gibbs.Bd -literal -offset indent 4744a775e8fSJustin T. Gibbsstruct HEADNAME *headp; 4754a775e8fSJustin T. Gibbs.Ed 4768f20a914SMike Pritchard.Pp 4774a775e8fSJustin T. Gibbs(The names 4784a775e8fSJustin T. Gibbs.Li head 4794a775e8fSJustin T. Gibbsand 4804a775e8fSJustin T. Gibbs.Li headp 4814a775e8fSJustin T. Gibbsare user selectable.) 4824a775e8fSJustin T. Gibbs.Pp 4834a775e8fSJustin T. GibbsThe macro 48403763fe0SJake Burkholder.Nm STAILQ_HEAD_INITIALIZER 48503763fe0SJake Burkholderevaluates to an initializer for the tail queue 48603763fe0SJake Burkholder.Fa head . 48703763fe0SJake Burkholder.Pp 48803763fe0SJake BurkholderThe macro 489d57e28adSThomas Moestl.Nm STAILQ_CONCAT 490d57e28adSThomas Moestlconcatenates the tail queue headed by 491d57e28adSThomas Moestl.Fa head2 492d57e28adSThomas Moestlonto the end of the one headed by 493d57e28adSThomas Moestl.Fa head1 494d57e28adSThomas Moestlremoving all entries from the former. 495d57e28adSThomas Moestl.Pp 496d57e28adSThomas MoestlThe macro 49779ea9bc4SAlexey Zelkin.Nm STAILQ_EMPTY 49879ea9bc4SAlexey Zelkinevaluates to true if there are no items on the tail queue. 49979ea9bc4SAlexey Zelkin.Pp 50079ea9bc4SAlexey ZelkinThe macro 5014a775e8fSJustin T. Gibbs.Nm STAILQ_ENTRY 5024a775e8fSJustin T. Gibbsdeclares a structure that connects the elements in 5034a775e8fSJustin T. Gibbsthe tail queue. 5044a775e8fSJustin T. Gibbs.Pp 5054a775e8fSJustin T. GibbsThe macro 50679ea9bc4SAlexey Zelkin.Nm STAILQ_FIRST 50779ea9bc4SAlexey Zelkinreturns the first item on the tail queue or NULL if the tail queue 50879ea9bc4SAlexey Zelkinis empty. 50979ea9bc4SAlexey Zelkin.Pp 51079ea9bc4SAlexey ZelkinThe macro 51179ea9bc4SAlexey Zelkin.Nm STAILQ_FOREACH 51279ea9bc4SAlexey Zelkintraverses the tail queue referenced by 51379ea9bc4SAlexey Zelkin.Fa head 51479ea9bc4SAlexey Zelkinin the forward direction, assigning each element 51579ea9bc4SAlexey Zelkinin turn to 51679ea9bc4SAlexey Zelkin.Fa var . 51779ea9bc4SAlexey Zelkin.Pp 51879ea9bc4SAlexey ZelkinThe macro 5192724bce2SAlexander Kabaev.Nm STAILQ_FOREACH_SAFE 5202724bce2SAlexander Kabaevtraverses the tail queue referenced by 5212724bce2SAlexander Kabaev.Fa head 5222724bce2SAlexander Kabaevin the forward direction, assigning each element 5232724bce2SAlexander Kabaevin turn to 5242724bce2SAlexander Kabaev.Fa var . 5252724bce2SAlexander KabaevHowever, unlike 5262724bce2SAlexander Kabaev.Fn STAILQ_FOREACH 5272724bce2SAlexander Kabaevhere it is permitted to both remove 5282724bce2SAlexander Kabaev.Fa var 5292724bce2SAlexander Kabaevas well as free it from within the loop safely without interfering with the 5302724bce2SAlexander Kabaevtraversal. 5312724bce2SAlexander Kabaev.Pp 5322724bce2SAlexander KabaevThe macro 5334a775e8fSJustin T. Gibbs.Nm STAILQ_INIT 5344a775e8fSJustin T. Gibbsinitializes the tail queue referenced by 5354a775e8fSJustin T. Gibbs.Fa head . 5364a775e8fSJustin T. Gibbs.Pp 5374a775e8fSJustin T. GibbsThe macro 5384a775e8fSJustin T. Gibbs.Nm STAILQ_INSERT_HEAD 5394a775e8fSJustin T. Gibbsinserts the new element 5404a775e8fSJustin T. Gibbs.Fa elm 5414a775e8fSJustin T. Gibbsat the head of the tail queue. 5424a775e8fSJustin T. Gibbs.Pp 5434a775e8fSJustin T. GibbsThe macro 5444a775e8fSJustin T. Gibbs.Nm STAILQ_INSERT_TAIL 5454a775e8fSJustin T. Gibbsinserts the new element 5464a775e8fSJustin T. Gibbs.Fa elm 5474a775e8fSJustin T. Gibbsat the end of the tail queue. 5484a775e8fSJustin T. Gibbs.Pp 5494a775e8fSJustin T. GibbsThe macro 5504a775e8fSJustin T. Gibbs.Nm STAILQ_INSERT_AFTER 5514a775e8fSJustin T. Gibbsinserts the new element 5524a775e8fSJustin T. Gibbs.Fa elm 5534a775e8fSJustin T. Gibbsafter the element 5544a775e8fSJustin T. Gibbs.Fa listelm . 5554a775e8fSJustin T. Gibbs.Pp 5564a775e8fSJustin T. GibbsThe macro 55779ea9bc4SAlexey Zelkin.Nm STAILQ_LAST 55879ea9bc4SAlexey Zelkinreturns the last item on the tail queue. 559982ba1cbSKirk McKusickIf the tail queue is empty the return value is 560982ba1cbSKirk McKusick.Dv NULL . 56179ea9bc4SAlexey Zelkin.Pp 56279ea9bc4SAlexey ZelkinThe macro 56379ea9bc4SAlexey Zelkin.Nm STAILQ_NEXT 56479ea9bc4SAlexey Zelkinreturns the next item on the tail queue, or NULL this item is the last. 56579ea9bc4SAlexey Zelkin.Pp 56679ea9bc4SAlexey ZelkinThe macro 5673d98b75bSEd Schouten.Nm STAILQ_REMOVE_AFTER 5683d98b75bSEd Schoutenremoves the element after 5693d98b75bSEd Schouten.Fa elm 5703d98b75bSEd Schoutenfrom the tail queue. Unlike 5713d98b75bSEd Schouten.Fa STAILQ_REMOVE , 5723d98b75bSEd Schoutenthis macro does not traverse the entire tail queue. 5733d98b75bSEd Schouten.Pp 5743d98b75bSEd SchoutenThe macro 5754a775e8fSJustin T. Gibbs.Nm STAILQ_REMOVE_HEAD 576ce900f03SAlfred Perlsteinremoves the element at the head of the tail queue. 5774a775e8fSJustin T. GibbsFor optimum efficiency, 5784a775e8fSJustin T. Gibbselements being removed from the head of the tail queue should 5794a775e8fSJustin T. Gibbsuse this macro explicitly rather than the generic 5804a775e8fSJustin T. Gibbs.Fa STAILQ_REMOVE 5814a775e8fSJustin T. Gibbsmacro. 5824a775e8fSJustin T. Gibbs.Pp 5834a775e8fSJustin T. GibbsThe macro 5844a775e8fSJustin T. Gibbs.Nm STAILQ_REMOVE 5854a775e8fSJustin T. Gibbsremoves the element 5864a775e8fSJustin T. Gibbs.Fa elm 5874a775e8fSJustin T. Gibbsfrom the tail queue. 5884a775e8fSJustin T. Gibbs.Sh SINGLY-LINKED TAIL QUEUE EXAMPLE 5894a775e8fSJustin T. Gibbs.Bd -literal 59003763fe0SJake BurkholderSTAILQ_HEAD(stailhead, entry) head = 59103763fe0SJake Burkholder STAILQ_HEAD_INITIALIZER(head); 5924a775e8fSJustin T. Gibbsstruct stailhead *headp; /* Singly-linked tail queue head. */ 5934a775e8fSJustin T. Gibbsstruct entry { 5944a775e8fSJustin T. Gibbs ... 5954a775e8fSJustin T. Gibbs STAILQ_ENTRY(entry) entries; /* Tail queue. */ 5964a775e8fSJustin T. Gibbs ... 5974a775e8fSJustin T. Gibbs} *n1, *n2, *n3, *np; 5984a775e8fSJustin T. Gibbs 5994a775e8fSJustin T. GibbsSTAILQ_INIT(&head); /* Initialize the queue. */ 6004a775e8fSJustin T. Gibbs 6014a775e8fSJustin T. Gibbsn1 = malloc(sizeof(struct entry)); /* Insert at the head. */ 6024a775e8fSJustin T. GibbsSTAILQ_INSERT_HEAD(&head, n1, entries); 6034a775e8fSJustin T. Gibbs 6044a775e8fSJustin T. Gibbsn1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ 6054a775e8fSJustin T. GibbsSTAILQ_INSERT_TAIL(&head, n1, entries); 6064a775e8fSJustin T. Gibbs 6074a775e8fSJustin T. Gibbsn2 = malloc(sizeof(struct entry)); /* Insert after. */ 6084a775e8fSJustin T. GibbsSTAILQ_INSERT_AFTER(&head, n1, n2, entries); 6094a775e8fSJustin T. Gibbs /* Deletion. */ 6104a775e8fSJustin T. GibbsSTAILQ_REMOVE(&head, n2, entry, entries); 6114a775e8fSJustin T. Gibbsfree(n2); 61203763fe0SJake Burkholder /* Deletion from the head. */ 61379ea9bc4SAlexey Zelkinn3 = STAILQ_FIRST(&head); 6144a775e8fSJustin T. GibbsSTAILQ_REMOVE_HEAD(&head, entries); 6154a775e8fSJustin T. Gibbsfree(n3); 6164a775e8fSJustin T. Gibbs /* Forward traversal. */ 61779ea9bc4SAlexey ZelkinSTAILQ_FOREACH(np, &head, entries) 6184a775e8fSJustin T. Gibbs np-> ... 6192724bce2SAlexander Kabaev /* Safe forward traversal. */ 6202724bce2SAlexander KabaevSTAILQ_FOREACH_SAFE(np, &head, entries, np_temp) { 6212724bce2SAlexander Kabaev np->do_stuff(); 6222724bce2SAlexander Kabaev ... 6232724bce2SAlexander Kabaev STAILQ_REMOVE(&head, np, entry, entries); 6242724bce2SAlexander Kabaev free(np); 6252724bce2SAlexander Kabaev} 6264a775e8fSJustin T. Gibbs /* TailQ Deletion. */ 62779ea9bc4SAlexey Zelkinwhile (!STAILQ_EMPTY(&head)) { 62803763fe0SJake Burkholder n1 = STAILQ_FIRST(&head); 629266e33fdSJohn Baldwin STAILQ_REMOVE_HEAD(&head, entries); 6304a775e8fSJustin T. Gibbs free(n1); 6314a775e8fSJustin T. Gibbs} 6324a775e8fSJustin T. Gibbs /* Faster TailQ Deletion. */ 63379ea9bc4SAlexey Zelkinn1 = STAILQ_FIRST(&head); 6344a775e8fSJustin T. Gibbswhile (n1 != NULL) { 63579ea9bc4SAlexey Zelkin n2 = STAILQ_NEXT(n1, entries); 6364a775e8fSJustin T. Gibbs free(n1); 6374a775e8fSJustin T. Gibbs n1 = n2; 6384a775e8fSJustin T. Gibbs} 6394a775e8fSJustin T. GibbsSTAILQ_INIT(&head); 6404a775e8fSJustin T. Gibbs.Ed 641afe61c15SRodney W. Grimes.Sh LISTS 642afe61c15SRodney W. GrimesA list is headed by a structure defined by the 643afe61c15SRodney W. Grimes.Nm LIST_HEAD 644afe61c15SRodney W. Grimesmacro. 645afe61c15SRodney W. GrimesThis structure contains a single pointer to the first element 646afe61c15SRodney W. Grimeson the list. 647afe61c15SRodney W. GrimesThe elements are doubly linked so that an arbitrary element can be 648afe61c15SRodney W. Grimesremoved without traversing the list. 6494a775e8fSJustin T. GibbsNew elements can be added to the list after an existing element, 6504a775e8fSJustin T. Gibbsbefore an existing element, or at the head of the list. 651afe61c15SRodney W. GrimesA 652afe61c15SRodney W. Grimes.Fa LIST_HEAD 653afe61c15SRodney W. Grimesstructure is declared as follows: 654afe61c15SRodney W. Grimes.Bd -literal -offset indent 655afe61c15SRodney W. GrimesLIST_HEAD(HEADNAME, TYPE) head; 656afe61c15SRodney W. Grimes.Ed 6578f20a914SMike Pritchard.Pp 658afe61c15SRodney W. Grimeswhere 659afe61c15SRodney W. Grimes.Fa HEADNAME 660afe61c15SRodney W. Grimesis the name of the structure to be defined, and 661afe61c15SRodney W. Grimes.Fa TYPE 662afe61c15SRodney W. Grimesis the type of the elements to be linked into the list. 663afe61c15SRodney W. GrimesA pointer to the head of the list can later be declared as: 664afe61c15SRodney W. Grimes.Bd -literal -offset indent 665afe61c15SRodney W. Grimesstruct HEADNAME *headp; 666afe61c15SRodney W. Grimes.Ed 6678f20a914SMike Pritchard.Pp 668afe61c15SRodney W. Grimes(The names 669afe61c15SRodney W. Grimes.Li head 670afe61c15SRodney W. Grimesand 671afe61c15SRodney W. Grimes.Li headp 672afe61c15SRodney W. Grimesare user selectable.) 673afe61c15SRodney W. Grimes.Pp 674afe61c15SRodney W. GrimesThe macro 67503763fe0SJake Burkholder.Nm LIST_HEAD_INITIALIZER 67603763fe0SJake Burkholderevaluates to an initializer for the list 67703763fe0SJake Burkholder.Fa head . 67803763fe0SJake Burkholder.Pp 67903763fe0SJake BurkholderThe macro 68079ea9bc4SAlexey Zelkin.Nm LIST_EMPTY 681ddbb94adSTom Rhodesevaluates to true if there are no elements in the list. 68279ea9bc4SAlexey Zelkin.Pp 68379ea9bc4SAlexey ZelkinThe macro 684afe61c15SRodney W. Grimes.Nm LIST_ENTRY 685afe61c15SRodney W. Grimesdeclares a structure that connects the elements in 686afe61c15SRodney W. Grimesthe list. 687afe61c15SRodney W. Grimes.Pp 688afe61c15SRodney W. GrimesThe macro 68979ea9bc4SAlexey Zelkin.Nm LIST_FIRST 69079ea9bc4SAlexey Zelkinreturns the first element in the list or NULL if the list 69179ea9bc4SAlexey Zelkinis empty. 69279ea9bc4SAlexey Zelkin.Pp 69379ea9bc4SAlexey ZelkinThe macro 69479ea9bc4SAlexey Zelkin.Nm LIST_FOREACH 69579ea9bc4SAlexey Zelkintraverses the list referenced by 69679ea9bc4SAlexey Zelkin.Fa head 69779ea9bc4SAlexey Zelkinin the forward direction, assigning each element in turn to 69879ea9bc4SAlexey Zelkin.Fa var . 69979ea9bc4SAlexey Zelkin.Pp 70079ea9bc4SAlexey ZelkinThe macro 7014250a68eSBosko Milekic.Nm LIST_FOREACH_SAFE 7024250a68eSBosko Milekictraverses the list referenced by 7034250a68eSBosko Milekic.Fa head 7044250a68eSBosko Milekicin the forward direction, assigning each element in turn to 7054250a68eSBosko Milekic.Fa var . 7064250a68eSBosko MilekicHowever, unlike 7074250a68eSBosko Milekic.Fn LIST_FOREACH 7084250a68eSBosko Milekichere it is permitted to both remove 7094250a68eSBosko Milekic.Fa var 7104250a68eSBosko Milekicas well as free it from within the loop safely without interfering with the 7114250a68eSBosko Milekictraversal. 7124250a68eSBosko Milekic.Pp 7134250a68eSBosko MilekicThe macro 714afe61c15SRodney W. Grimes.Nm LIST_INIT 715afe61c15SRodney W. Grimesinitializes the list referenced by 716afe61c15SRodney W. Grimes.Fa head . 717afe61c15SRodney W. Grimes.Pp 718afe61c15SRodney W. GrimesThe macro 719afe61c15SRodney W. Grimes.Nm LIST_INSERT_HEAD 720afe61c15SRodney W. Grimesinserts the new element 721afe61c15SRodney W. Grimes.Fa elm 722afe61c15SRodney W. Grimesat the head of the list. 723afe61c15SRodney W. Grimes.Pp 724afe61c15SRodney W. GrimesThe macro 725afe61c15SRodney W. Grimes.Nm LIST_INSERT_AFTER 726afe61c15SRodney W. Grimesinserts the new element 727afe61c15SRodney W. Grimes.Fa elm 728afe61c15SRodney W. Grimesafter the element 729afe61c15SRodney W. Grimes.Fa listelm . 730afe61c15SRodney W. Grimes.Pp 731afe61c15SRodney W. GrimesThe macro 7327658b0a2SJustin T. Gibbs.Nm LIST_INSERT_BEFORE 7337658b0a2SJustin T. Gibbsinserts the new element 7347658b0a2SJustin T. Gibbs.Fa elm 7357658b0a2SJustin T. Gibbsbefore the element 7367658b0a2SJustin T. Gibbs.Fa listelm . 7377658b0a2SJustin T. Gibbs.Pp 7387658b0a2SJustin T. GibbsThe macro 73979ea9bc4SAlexey Zelkin.Nm LIST_NEXT 74079ea9bc4SAlexey Zelkinreturns the next element in the list, or NULL if this is the last. 74179ea9bc4SAlexey Zelkin.Pp 74279ea9bc4SAlexey ZelkinThe macro 743afe61c15SRodney W. Grimes.Nm LIST_REMOVE 744afe61c15SRodney W. Grimesremoves the element 745afe61c15SRodney W. Grimes.Fa elm 746afe61c15SRodney W. Grimesfrom the list. 747afe61c15SRodney W. Grimes.Sh LIST EXAMPLE 748afe61c15SRodney W. Grimes.Bd -literal 74903763fe0SJake BurkholderLIST_HEAD(listhead, entry) head = 75003763fe0SJake Burkholder LIST_HEAD_INITIALIZER(head); 751afe61c15SRodney W. Grimesstruct listhead *headp; /* List head. */ 752afe61c15SRodney W. Grimesstruct entry { 753afe61c15SRodney W. Grimes ... 754afe61c15SRodney W. Grimes LIST_ENTRY(entry) entries; /* List. */ 755afe61c15SRodney W. Grimes ... 7564250a68eSBosko Milekic} *n1, *n2, *n3, *np, *np_temp; 757afe61c15SRodney W. Grimes 758afe61c15SRodney W. GrimesLIST_INIT(&head); /* Initialize the list. */ 759afe61c15SRodney W. Grimes 760afe61c15SRodney W. Grimesn1 = malloc(sizeof(struct entry)); /* Insert at the head. */ 761afe61c15SRodney W. GrimesLIST_INSERT_HEAD(&head, n1, entries); 762afe61c15SRodney W. Grimes 763afe61c15SRodney W. Grimesn2 = malloc(sizeof(struct entry)); /* Insert after. */ 764afe61c15SRodney W. GrimesLIST_INSERT_AFTER(n1, n2, entries); 7657658b0a2SJustin T. Gibbs 7667658b0a2SJustin T. Gibbsn3 = malloc(sizeof(struct entry)); /* Insert before. */ 7677658b0a2SJustin T. GibbsLIST_INSERT_BEFORE(n2, n3, entries); 7687658b0a2SJustin T. Gibbs 7697658b0a2SJustin T. GibbsLIST_REMOVE(n2, entries); /* Deletion. */ 7707658b0a2SJustin T. Gibbsfree(n2); 771afe61c15SRodney W. Grimes /* Forward traversal. */ 77279ea9bc4SAlexey ZelkinLIST_FOREACH(np, &head, entries) 773afe61c15SRodney W. Grimes np-> ... 774afe61c15SRodney W. Grimes 7754250a68eSBosko Milekic /* Safe forward traversal. */ 7764250a68eSBosko MilekicLIST_FOREACH_SAFE(np, &head, entries, np_temp) { 7774250a68eSBosko Milekic np->do_stuff(); 7784250a68eSBosko Milekic ... 7794250a68eSBosko Milekic LIST_REMOVE(np, entries); 7804250a68eSBosko Milekic free(np); 7814250a68eSBosko Milekic} 7824250a68eSBosko Milekic 78379ea9bc4SAlexey Zelkinwhile (!LIST_EMPTY(&head)) { /* List Deletion. */ 78479ea9bc4SAlexey Zelkin n1 = LIST_FIRST(&head); 7857658b0a2SJustin T. Gibbs LIST_REMOVE(n1, entries); 7867658b0a2SJustin T. Gibbs free(n1); 7877658b0a2SJustin T. Gibbs} 7887658b0a2SJustin T. Gibbs 78903763fe0SJake Burkholdern1 = LIST_FIRST(&head); /* Faster List Deletion. */ 7907658b0a2SJustin T. Gibbswhile (n1 != NULL) { 79179ea9bc4SAlexey Zelkin n2 = LIST_NEXT(n1, entries); 7927658b0a2SJustin T. Gibbs free(n1); 7937658b0a2SJustin T. Gibbs n1 = n2; 7947658b0a2SJustin T. Gibbs} 7957658b0a2SJustin T. GibbsLIST_INIT(&head); 796afe61c15SRodney W. Grimes.Ed 797afe61c15SRodney W. Grimes.Sh TAIL QUEUES 798afe61c15SRodney W. GrimesA tail queue is headed by a structure defined by the 799afe61c15SRodney W. Grimes.Nm TAILQ_HEAD 800afe61c15SRodney W. Grimesmacro. 801afe61c15SRodney W. GrimesThis structure contains a pair of pointers, 802afe61c15SRodney W. Grimesone to the first element in the tail queue and the other to 803afe61c15SRodney W. Grimesthe last element in the tail queue. 804afe61c15SRodney W. GrimesThe elements are doubly linked so that an arbitrary element can be 805afe61c15SRodney W. Grimesremoved without traversing the tail queue. 806afe61c15SRodney W. GrimesNew elements can be added to the tail queue after an existing element, 8074a775e8fSJustin T. Gibbsbefore an existing element, at the head of the tail queue, 8084a775e8fSJustin T. Gibbsor at the end of the tail queue. 809afe61c15SRodney W. GrimesA 810afe61c15SRodney W. Grimes.Fa TAILQ_HEAD 811afe61c15SRodney W. Grimesstructure is declared as follows: 812afe61c15SRodney W. Grimes.Bd -literal -offset indent 813afe61c15SRodney W. GrimesTAILQ_HEAD(HEADNAME, TYPE) head; 814afe61c15SRodney W. Grimes.Ed 8158f20a914SMike Pritchard.Pp 816afe61c15SRodney W. Grimeswhere 817afe61c15SRodney W. Grimes.Li HEADNAME 818afe61c15SRodney W. Grimesis the name of the structure to be defined, and 819afe61c15SRodney W. Grimes.Li TYPE 820afe61c15SRodney W. Grimesis the type of the elements to be linked into the tail queue. 821afe61c15SRodney W. GrimesA pointer to the head of the tail queue can later be declared as: 822afe61c15SRodney W. Grimes.Bd -literal -offset indent 823afe61c15SRodney W. Grimesstruct HEADNAME *headp; 824afe61c15SRodney W. Grimes.Ed 8258f20a914SMike Pritchard.Pp 826afe61c15SRodney W. Grimes(The names 827afe61c15SRodney W. Grimes.Li head 828afe61c15SRodney W. Grimesand 829afe61c15SRodney W. Grimes.Li headp 830afe61c15SRodney W. Grimesare user selectable.) 831afe61c15SRodney W. Grimes.Pp 832afe61c15SRodney W. GrimesThe macro 83303763fe0SJake Burkholder.Nm TAILQ_HEAD_INITIALIZER 83403763fe0SJake Burkholderevaluates to an initializer for the tail queue 83503763fe0SJake Burkholder.Fa head . 83603763fe0SJake Burkholder.Pp 83703763fe0SJake BurkholderThe macro 838d57e28adSThomas Moestl.Nm TAILQ_CONCAT 839d57e28adSThomas Moestlconcatenates the tail queue headed by 840d57e28adSThomas Moestl.Fa head2 841d57e28adSThomas Moestlonto the end of the one headed by 842d57e28adSThomas Moestl.Fa head1 843d57e28adSThomas Moestlremoving all entries from the former. 844d57e28adSThomas Moestl.Pp 845d57e28adSThomas MoestlThe macro 846c5c15c16SPoul-Henning Kamp.Nm TAILQ_EMPTY 847c5c15c16SPoul-Henning Kampevaluates to true if there are no items on the tail queue. 848c5c15c16SPoul-Henning Kamp.Pp 849c5c15c16SPoul-Henning KampThe macro 850afe61c15SRodney W. Grimes.Nm TAILQ_ENTRY 851afe61c15SRodney W. Grimesdeclares a structure that connects the elements in 852afe61c15SRodney W. Grimesthe tail queue. 853afe61c15SRodney W. Grimes.Pp 854afe61c15SRodney W. GrimesThe macro 855c5c15c16SPoul-Henning Kamp.Nm TAILQ_FIRST 856c5c15c16SPoul-Henning Kampreturns the first item on the tail queue or NULL if the tail queue 857c5c15c16SPoul-Henning Kampis empty. 858c5c15c16SPoul-Henning Kamp.Pp 859c5c15c16SPoul-Henning KampThe macro 86079ea9bc4SAlexey Zelkin.Nm TAILQ_FOREACH 86179ea9bc4SAlexey Zelkintraverses the tail queue referenced by 86279ea9bc4SAlexey Zelkin.Fa head 86379ea9bc4SAlexey Zelkinin the forward direction, assigning each element in turn to 86479ea9bc4SAlexey Zelkin.Fa var . 865fb5293cfSRuslan Ermilov.Fa var 866fb5293cfSRuslan Ermilovis set to 867fb5293cfSRuslan Ermilov.Dv NULL 868fb5293cfSRuslan Ermilovif the loop completes normally, or if there were no elements. 86979ea9bc4SAlexey Zelkin.Pp 87079ea9bc4SAlexey ZelkinThe macro 8716c1d0fbfSArchie Cobbs.Nm TAILQ_FOREACH_REVERSE 8726c1d0fbfSArchie Cobbstraverses the tail queue referenced by 8736c1d0fbfSArchie Cobbs.Fa head 8746c1d0fbfSArchie Cobbsin the reverse direction, assigning each element in turn to 8756c1d0fbfSArchie Cobbs.Fa var . 8766c1d0fbfSArchie Cobbs.Pp 8772724bce2SAlexander KabaevThe macros 8782724bce2SAlexander Kabaev.Nm TAILQ_FOREACH_SAFE 8792724bce2SAlexander Kabaevand 8802724bce2SAlexander Kabaev.Nm TAILQ_FOREACH_REVERSE_SAFE 8812724bce2SAlexander Kabaevtraverse the list referenced by 8822724bce2SAlexander Kabaev.Fa head 8832724bce2SAlexander Kabaevin the forward or reverse direction respectively, 8842724bce2SAlexander Kabaevassigning each element in turn to 8852724bce2SAlexander Kabaev.Fa var . 8863b96c71fSMike PritchardHowever, unlike their unsafe counterparts, 8872724bce2SAlexander Kabaev.Nm TAILQ_FOREACH 8882724bce2SAlexander Kabaevand 8892724bce2SAlexander Kabaev.Nm TAILQ_FOREACH_REVERSE 8902724bce2SAlexander Kabaevpermit to both remove 8912724bce2SAlexander Kabaev.Fa var 8922724bce2SAlexander Kabaevas well as free it from within the loop safely without interfering with the 8932724bce2SAlexander Kabaevtraversal. 8942724bce2SAlexander Kabaev.Pp 8956c1d0fbfSArchie CobbsThe macro 896afe61c15SRodney W. Grimes.Nm TAILQ_INIT 897afe61c15SRodney W. Grimesinitializes the tail queue referenced by 898afe61c15SRodney W. Grimes.Fa head . 899afe61c15SRodney W. Grimes.Pp 900afe61c15SRodney W. GrimesThe macro 901afe61c15SRodney W. Grimes.Nm TAILQ_INSERT_HEAD 902afe61c15SRodney W. Grimesinserts the new element 903afe61c15SRodney W. Grimes.Fa elm 904afe61c15SRodney W. Grimesat the head of the tail queue. 905afe61c15SRodney W. Grimes.Pp 906afe61c15SRodney W. GrimesThe macro 907afe61c15SRodney W. Grimes.Nm TAILQ_INSERT_TAIL 908afe61c15SRodney W. Grimesinserts the new element 909afe61c15SRodney W. Grimes.Fa elm 910afe61c15SRodney W. Grimesat the end of the tail queue. 911afe61c15SRodney W. Grimes.Pp 912afe61c15SRodney W. GrimesThe macro 913afe61c15SRodney W. Grimes.Nm TAILQ_INSERT_AFTER 914afe61c15SRodney W. Grimesinserts the new element 915afe61c15SRodney W. Grimes.Fa elm 916afe61c15SRodney W. Grimesafter the element 917afe61c15SRodney W. Grimes.Fa listelm . 918afe61c15SRodney W. Grimes.Pp 919afe61c15SRodney W. GrimesThe macro 9207658b0a2SJustin T. Gibbs.Nm TAILQ_INSERT_BEFORE 9217658b0a2SJustin T. Gibbsinserts the new element 9227658b0a2SJustin T. Gibbs.Fa elm 9237658b0a2SJustin T. Gibbsbefore the element 9247658b0a2SJustin T. Gibbs.Fa listelm . 9257658b0a2SJustin T. Gibbs.Pp 9267658b0a2SJustin T. GibbsThe macro 927c5c15c16SPoul-Henning Kamp.Nm TAILQ_LAST 928c5c15c16SPoul-Henning Kampreturns the last item on the tail queue. 929982ba1cbSKirk McKusickIf the tail queue is empty the return value is 930982ba1cbSKirk McKusick.Dv NULL . 931c5c15c16SPoul-Henning Kamp.Pp 932c5c15c16SPoul-Henning KampThe macro 933c5c15c16SPoul-Henning Kamp.Nm TAILQ_NEXT 93479ea9bc4SAlexey Zelkinreturns the next item on the tail queue, or NULL if this item is the last. 93579ea9bc4SAlexey Zelkin.Pp 93679ea9bc4SAlexey ZelkinThe macro 93779ea9bc4SAlexey Zelkin.Nm TAILQ_PREV 93879ea9bc4SAlexey Zelkinreturns the previous item on the tail queue, or NULL if this item 93979ea9bc4SAlexey Zelkinis the first. 940c5c15c16SPoul-Henning Kamp.Pp 941c5c15c16SPoul-Henning KampThe macro 942afe61c15SRodney W. Grimes.Nm TAILQ_REMOVE 943afe61c15SRodney W. Grimesremoves the element 944afe61c15SRodney W. Grimes.Fa elm 945afe61c15SRodney W. Grimesfrom the tail queue. 946afe61c15SRodney W. Grimes.Sh TAIL QUEUE EXAMPLE 947afe61c15SRodney W. Grimes.Bd -literal 94803763fe0SJake BurkholderTAILQ_HEAD(tailhead, entry) head = 94903763fe0SJake Burkholder TAILQ_HEAD_INITIALIZER(head); 950afe61c15SRodney W. Grimesstruct tailhead *headp; /* Tail queue head. */ 951afe61c15SRodney W. Grimesstruct entry { 952afe61c15SRodney W. Grimes ... 953afe61c15SRodney W. Grimes TAILQ_ENTRY(entry) entries; /* Tail queue. */ 954afe61c15SRodney W. Grimes ... 9557658b0a2SJustin T. Gibbs} *n1, *n2, *n3, *np; 956afe61c15SRodney W. Grimes 957afe61c15SRodney W. GrimesTAILQ_INIT(&head); /* Initialize the queue. */ 958afe61c15SRodney W. Grimes 959afe61c15SRodney W. Grimesn1 = malloc(sizeof(struct entry)); /* Insert at the head. */ 960afe61c15SRodney W. GrimesTAILQ_INSERT_HEAD(&head, n1, entries); 961afe61c15SRodney W. Grimes 962afe61c15SRodney W. Grimesn1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ 963afe61c15SRodney W. GrimesTAILQ_INSERT_TAIL(&head, n1, entries); 964afe61c15SRodney W. Grimes 965afe61c15SRodney W. Grimesn2 = malloc(sizeof(struct entry)); /* Insert after. */ 966afe61c15SRodney W. GrimesTAILQ_INSERT_AFTER(&head, n1, n2, entries); 9677658b0a2SJustin T. Gibbs 9687658b0a2SJustin T. Gibbsn3 = malloc(sizeof(struct entry)); /* Insert before. */ 9693652ff55SJustin T. GibbsTAILQ_INSERT_BEFORE(n2, n3, entries); 9707658b0a2SJustin T. Gibbs 9717658b0a2SJustin T. GibbsTAILQ_REMOVE(&head, n2, entries); /* Deletion. */ 9727658b0a2SJustin T. Gibbsfree(n2); 973afe61c15SRodney W. Grimes /* Forward traversal. */ 97479ea9bc4SAlexey ZelkinTAILQ_FOREACH(np, &head, entries) 975afe61c15SRodney W. Grimes np-> ... 9762724bce2SAlexander Kabaev /* Safe forward traversal. */ 9772724bce2SAlexander KabaevTAILQ_FOREACH_SAFE(np, &head, entries, np_temp) { 9782724bce2SAlexander Kabaev np->do_stuff(); 9792724bce2SAlexander Kabaev ... 9802724bce2SAlexander Kabaev TAILQ_REMOVE(&head, np, entries); 9812724bce2SAlexander Kabaev free(np); 9822724bce2SAlexander Kabaev} 9836c1d0fbfSArchie Cobbs /* Reverse traversal. */ 9846c1d0fbfSArchie CobbsTAILQ_FOREACH_REVERSE(np, &head, tailhead, entries) 9856c1d0fbfSArchie Cobbs np-> ... 9867658b0a2SJustin T. Gibbs /* TailQ Deletion. */ 987d6c63818SMark Murraywhile (!TAILQ_EMPTY(&head)) { 988c5c15c16SPoul-Henning Kamp n1 = TAILQ_FIRST(&head); 98979ea9bc4SAlexey Zelkin TAILQ_REMOVE(&head, n1, entries); 9907658b0a2SJustin T. Gibbs free(n1); 9917658b0a2SJustin T. Gibbs} 9927658b0a2SJustin T. Gibbs /* Faster TailQ Deletion. */ 993c5c15c16SPoul-Henning Kampn1 = TAILQ_FIRST(&head); 9947658b0a2SJustin T. Gibbswhile (n1 != NULL) { 995c5c15c16SPoul-Henning Kamp n2 = TAILQ_NEXT(n1, entries); 9967658b0a2SJustin T. Gibbs free(n1); 9977658b0a2SJustin T. Gibbs n1 = n2; 9987658b0a2SJustin T. Gibbs} 9997658b0a2SJustin T. GibbsTAILQ_INIT(&head); 1000afe61c15SRodney W. Grimes.Ed 1001afe61c15SRodney W. Grimes.Sh HISTORY 1002afe61c15SRodney W. GrimesThe 1003afe61c15SRodney W. Grimes.Nm queue 100421421932SMike Pritchardfunctions first appeared in 100521421932SMike Pritchard.Bx 4.4 . 1006