2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)queue.3 8.2 (Berkeley) 1/24/94
35 .\" 2007-12-08, mtk, Converted from mdoc to man macros
37 .\" Japanese Version Copyright (c) 2004 Yuichi SATO
38 .\" all rights reserved.
39 .\" Translated Thu Sep 2 04:41:11 JST 2004
40 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
42 .\"WORD: circular queue ½Û´Ä¥¥å¡¼
44 .TH QUEUE 3 2007-12-28 "Linux" "Linux Programmer's Manual"
47 .\"O LIST_ENTRY, LIST_HEAD, LIST_INIT, LIST_INSERT_AFTER, \
48 .\"O LIST_INSERT_HEAD, LIST_REMOVE, TAILQ_ENTRY, TAILQ_HEAD, \
49 .\"O TAILQ_INIT, TAILQ_INSERT_AFTER, TAILQ_INSERT_HEAD, TAILQ_INSERT_TAIL, \
50 .\"O TAILQ_REMOVE, CIRCLEQ_ENTRY, CIRCLEQ_HEAD, CIRCLEQ_INIT, \
51 .\"O CIRCLEQ_INSERT_AFTER, CIRCLEQ_INSERT_BEFORE, \
52 .\"O CIRCLEQ_INSERT_HEAD, CIRCLEQ_INSERT_TAIL, \
53 .\"O CIRCLEQ_REMOVE \- implementations of lists, tail queues, and circular queues
54 LIST_ENTRY, LIST_HEAD, LIST_INIT, LIST_INSERT_AFTER, \
55 LIST_INSERT_HEAD, LIST_REMOVE, TAILQ_ENTRY, TAILQ_HEAD, \
56 TAILQ_INIT, TAILQ_INSERT_AFTER, TAILQ_INSERT_HEAD, TAILQ_INSERT_TAIL, \
57 TAILQ_REMOVE, CIRCLEQ_ENTRY, CIRCLEQ_HEAD, CIRCLEQ_INIT, \
58 CIRCLEQ_INSERT_AFTER, CIRCLEQ_INSERT_BEFORE, \
59 CIRCLEQ_INSERT_HEAD, CIRCLEQ_INSERT_TAIL, \
60 CIRCLEQ_REMOVE \- ¥ê¥¹¥È¡¦¥Æ¡¼¥ë (tail) ¥¥å¡¼¡¦½Û´Ä¥¥å¡¼¤Î¼ÂÁõ
62 .\"Osato: tail queue ¤ÎÎɤ¤Ìõ¸ì¤¬Ê¬¤«¤é¤Ê¤¤¤Î¤Ç¡¢¤È¤ê¤¢¤¨¤º¥«¥¿¥«¥Ê¤Ë¤¹¤ë¡£
67 .B #include <sys/queue.h>
69 .BI "LIST_ENTRY(" TYPE );
70 .BI "LIST_HEAD(" HEADNAME ", " TYPE );
71 .BI "LIST_INIT(LIST_HEAD *" head );
72 .BI "LIST_INSERT_AFTER(LIST_ENTRY *" listelm ", "
73 .BI " TYPE *" elm ", LIST_ENTRY " NAME );
74 .BI "LIST_INSERT_HEAD(LIST_HEAD *" head ", "
75 .BI " TYPE *" elm ", LIST_ENTRY " NAME );
76 .BI "LIST_REMOVE(TYPE *" elm ", LIST_ENTRY " NAME );
78 .BI "TAILQ_ENTRY(" TYPE );
79 .BI "TAILQ_HEAD("HEADNAME ", " TYPE );
80 .BI "TAILQ_INIT(TAILQ_HEAD *" head );
81 .BI "TAILQ_INSERT_AFTER(TAILQ_HEAD *" head ", TYPE *" listelm ", "
82 .BI " TYPE *" elm ", TAILQ_ENTRY " NAME );
83 .BI "TAILQ_INSERT_HEAD(TAILQ_HEAD *" head ", "
84 .BI " TYPE *" elm ", TAILQ_ENTRY " NAME );
85 .BI "TAILQ_INSERT_TAIL(TAILQ_HEAD *" head ", "
86 .BI " TYPE *" elm ", TAILQ_ENTRY " NAME );
87 .BI "TAILQ_REMOVE(TAILQ_HEAD *" head ", TYPE *" elm ", TAILQ_ENTRY " NAME );
89 .BI CIRCLEQ_ENTRY( TYPE );
90 .BI "CIRCLEQ_HEAD(" HEADNAME ", " TYPE );
91 .BI "CIRCLEQ_INIT(CIRCLEQ_HEAD *" head );
92 .BI "CIRCLEQ_INSERT_AFTER(CIRCLEQ_HEAD *" head ", TYPE *" listelm ", "
93 .BI " TYPE *" elm ", CIRCLEQ_ENTRY " NAME );
94 .BI "CIRCLEQ_INSERT_BEFORE(CIRCLEQ_HEAD *" head ", TYPE *" listelm ", "
95 .BI " TYPE *" elm ", CIRCLEQ_ENTRY " NAME );
96 .BI "CIRCLEQ_INSERT_HEAD(CIRCLEQ_HEAD *" head ", "
97 .BI " TYPE *" elm ", CIRCLEQ_ENTRY " NAME );
98 .BI "CIRCLEQ_INSERT_TAIL(CIRCLEQ_HEAD *" head ", "
99 .BI " TYPE *" elm ", CIRCLEQ_ENTRY " NAME );
100 .BI "CIRCLEQ_REMOVE(CIRCLEQ_HEAD *" head ", "
101 .BI " TYPE *" elm ", CIRCLEQ_ENTRY " NAME );
105 .\"O These macros define and operate on three types of data structures:
106 .\"O lists, tail queues, and circular queues.
107 .\"O All three structures support the following functionality:
108 ¤³¤ì¤é¤Î¥Þ¥¯¥í¤Ï¡¢¼¡¤Î 3 ¤Ä¤Î¥Ç¡¼¥¿¹½Â¤¤òÄêµÁ¤·¤ÆÁàºî¤¹¤ë:
109 ¥ê¥¹¥È¡¦¥Æ¡¼¥ë¥¥å¡¼¡¦½Û´Ä¥¥å¡¼¡£
110 3 ¤Ä¤Î¥Ç¡¼¥¿¹½Â¤¤¹¤Ù¤Æ¤Ë¤ª¤¤¤Æ°Ê²¼¤Îµ¡Ç½¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë:
115 .\"O Insertion of a new entry at the head of the list.
116 ¿·¤¿¤Ê¥¨¥ó¥È¥ê¤ò¥ê¥¹¥È¤ÎÀèƬ¤ËÁÞÆþ¤¹¤ë¡£
118 .\"O Insertion of a new entry after any element in the list.
119 ¿·¤¿¤Ê¥¨¥ó¥È¥ê¤ò¥ê¥¹¥È¤Î¤É¤ÎÍ×ÁǤè¤ê¤â¸å¤ËÁÞÆþ¤¹¤ë¡£
121 .\"O Removal of any entry in the list.
122 ¥ê¥¹¥È¤ÎǤ°Õ¤Î¥¨¥ó¥È¥ê¤òºï½ü¤¹¤ë¡£
124 .\"O Forward traversal through the list.
125 ¥ê¥¹¥È¤ò½çÊý¸þ¤Ëé¤ë¡£
129 .\"O Lists are the simplest of the three data structures and support
130 .\"O only the above functionality.
131 ¥ê¥¹¥È¤Ï 3 ¤Ä¤Î¥Ç¡¼¥¿¹½Â¤¤ÎÃæ¤ÇºÇ¤âñ½ã¤Ç¤¢¤ê¡¢
132 ¾åµ¤Îµ¡Ç½¤Î¤ß¤ò¥µ¥Ý¡¼¥È¤¹¤ë¡£
134 .\"O Tail queues add the following functionality:
135 ¥Æ¡¼¥ë¥¥å¡¼¤Ï°Ê²¼¤Îµ¡Ç½¤òÄɲ乤ë:
138 .\"O Entries can be added at the end of a list.
139 ¥¨¥ó¥È¥ê¤ò¥ê¥¹¥È¤ÎºÇ¸å¤ËÄɲäǤ¤ë¡£
148 .\"O All list insertions and removals must specify the head of the list.
149 Á´¤Æ¤Î¥ê¥¹¥ÈÁÞÆþ¤Èºï½ü¤Ë¤ª¤¤¤Æ¡¢¥ê¥¹¥È¤ÎÀèƬ¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
151 .\"O Each head entry requires two pointers rather than one.
152 ³ÆÀèƬ¥¨¥ó¥È¥ê¤Ï 1 ¤Ä¤Ç¤Ï¤Ê¤¯ 2 ¤Ä¤Î¥Ý¥¤¥ó¥¿¤òɬÍפȤ¹¤ë¡£
154 .\"O Code size is about 15% greater and operations run about 20% slower
156 ¥ê¥¹¥È¤ÈÈæ¤Ù¤Æ¡¢¥³¡¼¥É¥µ¥¤¥º¤Ï 15% Â礤¯¤Ê¤ê¡¢Áàºî¤Ï 20% ÃÙ¤¯¤Ê¤ë¡£
160 .\"O Circular queues add the following functionality:
161 ½Û´Ä¥¥å¡¼¤Ï°Ê²¼¤Îµ¡Ç½¤òÄɲ乤ë:
166 .\"O Entries can be added at the end of a list.
167 ¥¨¥ó¥È¥ê¤ò¥ê¥¹¥È¤ÎºÇ¸å¤ËÄɲäǤ¤ë¡£
169 .\"O Entries can be added before another entry.
170 ¥¨¥ó¥È¥ê¤ò¾¤Î¥¨¥ó¥È¥ê¤ÎÁ°¤ËÄɲäǤ¤ë¡£
172 .\"O They may be traversed backwards, from tail to head.
173 µÕÊý¸þ¤ËËöÈø¤«¤éÀèƬ¤Øé¤ë¤³¤È¤¬¤Ç¤¤ë¡£
183 .\"O All list insertions and removals must specify the head of the list.
184 Á´¤Æ¤Î¥ê¥¹¥ÈÁÞÆþ¤Èºï½ü¤Ë¤ª¤¤¤Æ¡¢¥ê¥¹¥È¤ÎÀèƬ¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
186 .\"O Each head entry requires two pointers rather than one.
187 ³ÆÀèƬ¥¨¥ó¥È¥ê¤Ï 1 ¤Ä¤Ç¤Ï¤Ê¤¯ 2 ¤Ä¤Î¥Ý¥¤¥ó¥¿¤òɬÍפȤ¹¤ë¡£
189 .\"O The termination condition for traversal is more complex.
190 é¤ëºÝ¤Î½ªÎ»¾ò·ï¤¬¤è¤êÊ£»¨¤Ç¤¢¤ë¡£
192 .\"O Code size is about 40% greater and operations run about 45% slower
194 ¥ê¥¹¥È¤ÈÈæ¤Ù¤Æ¡¢¥³¡¼¥É¥µ¥¤¥º¤Ï 40% Â礤¯¤Ê¤ê¡¢Áàºî¤Ï 45% ÃÙ¤¯¤Ê¤ë¡£
198 .\"O In the macro definitions,
200 .\"O is the name of a user-defined structure,
201 .\"O that must contain a field of type
202 .\"O .BR LIST_ENTRY ,
203 .\"O .BR TAILQ_ENTRY ,
205 .\"O .BR CIRCLEQ_ENTRY ,
210 ¤Ï¥æ¡¼¥¶ÄêµÁ¹½Â¤ÂΤÎ̾Á°¤Ç¤¢¤ê¡¢
214 ¤Î²¿¤ì¤«·¿¤Î¥Õ¥£¡¼¥ë¥É¤È
217 ¤ò´Þ¤Þ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
220 .\"O is the name of a user-defined structure that must be declared
221 .\"O using the macros
223 .\"O .BR TAILQ_HEAD ,
225 .\"O .BR CIRCLEQ_HEAD .
228 ¤Ï¥æ¡¼¥¶ÄêµÁ¹½Â¤ÂΤÎ̾Á°¤Ç¤¢¤ê¡¢
233 ¤òÍѤ¤¤ÆÀë¸À¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
234 .\"O See the examples below for further explanation of how these
235 .\"O macros are used.
236 ¤³¤ì¤é¤Î¥Þ¥¯¥í¤¬¤É¤Î¤è¤¦¤Ë»È¤ï¤ì¤ë¤«¤Ë¤Ä¤¤¤Æ¤Î¹¹¤Ê¤ëÀâÌÀ¤Ï¡¢
237 °Ê²¼¤ÎÎã¤ò»²¾È¤¹¤ë¤³¤È¡£
240 .\"O A list is headed by a structure defined by the
245 ¥Þ¥¯¥í¤ÇÄêµÁ¤µ¤ì¤ë¹½Â¤ÂΤ¬ÃÖ¤«¤ì¤ë¡£
246 .\"O This structure contains a single pointer to the first element
248 ¤³¤Î¹½Â¤ÂΤϥꥹ¥È¤ÎºÇ½é¤ÎÍ×ÁǤؤΥݥ¤¥ó¥¿¤ò 1 ¤Ä´Þ¤à¡£
249 .\"O The elements are doubly linked so that an arbitrary element can be
250 .\"O removed without traversing the list.
251 Í×ÁÇ¤Ï 2 ½Å¤Ë¥ê¥ó¥¯¤µ¤ì¤Æ¤ª¤ê¡¢
252 Ǥ°Õ¤ÎÍ×ÁǤϥꥹ¥È¤òé¤é¤º¤Ëºï½ü¤Ç¤¤ë¡£
253 .\"O New elements can be added to the list after an existing element or
254 .\"O at the head of the list.
255 ¿·¤·¤¤Í×ÁǤϴû¸¤ÎÍ×ÁǤθå¤Þ¤¿¤Ï¥ê¥¹¥È¤ÎÀèƬ¤ËÄɲäǤ¤ë¡£
258 .\"O structure is declared as follows:
260 ¹½Â¤ÂΤϰʲ¼¤Î¤è¤¦¤ËÀë¸À¤µ¤ì¤Æ¤¤¤ë:
264 LIST_HEAD(HEADNAME, TYPE) head;
270 .\"O is the name of the structure to be defined, and
272 .\"O is the type of the elements to be linked into the list.
275 ¤ÏÄêµÁ¤µ¤ì¤ë¹½Â¤ÂΤÎ̾Á°¤Ç¤¢¤ê¡¢
277 ¤Ï¥ê¥ó¥¯Æâ¤Ç¥ê¥ó¥¯¤µ¤ì¤ëÍ×ÁǤη¿¤Ç¤¢¤ë¡£
278 .\"O A pointer to the head of the list can later be declared as:
279 ¥ê¥¹¥È¤ÎÀèƬ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ï¡¢¤½¤Î¸å¤Ç¼¡¤Î¤è¤¦¤ËÀë¸À¤µ¤ì¤ë:
283 struct HEADNAME *headp;
291 .\"O are user selectable.)
296 ¤Ï¥æ¡¼¥¶¤¬ÁªÂò¤Ç¤¤ë¡£)
300 .\"O declares a structure that connects the elements in
304 ¤Ï¥ê¥¹¥È¤ÎÍ×ÁǤòÀܳ¤¹¤ë¹½Â¤ÂΤòÀë¸À¤¹¤ë¡£
308 .\"O initializes the list referenced by
314 ¤Ç»²¾È¤µ¤ì¤ë¥ê¥¹¥È¤ò½é´ü²½¤¹¤ë¡£
317 .\"O .B LIST_INSERT_HEAD
318 .\"O inserts the new element
320 .\"O at the head of the list.
325 ¤ò¥ê¥¹¥È¤ÎÀèƬ¤ËÁÞÆþ¤¹¤ë¡£
328 .\"O .B LIST_INSERT_AFTER
329 .\"O inserts the new element
331 .\"O after the element
343 .\"O removes the element
350 ¤ò¥ê¥¹¥È¤«¤éºï½ü¤¹¤ë¡£
351 .\"O .SS LIST EXAMPLE
355 LIST_HEAD(listhead, entry) head;
356 .\"O struct listhead *headp; /* List head. */
357 struct listhead *headp; /* ¥ê¥¹¥È¤ÎÀèƬ¡£*/
360 .\"O LIST_ENTRY(entry) entries; /* List. */
363 LIST_ENTRY(entry) entries; /* ¥ê¥¹¥È¡£ */
367 .\"O LIST_INIT(&head); /* Initialize the list. */
368 LIST_INIT(&head); /* ¥ê¥¹¥È¤ò½é´ü²½¤¹¤ë¡£*/
370 .\"O n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
371 n1 = malloc(sizeof(struct entry)); /* ÀèƬ¤ËÁÞÆþ¤¹¤ë¡£*/
372 LIST_INSERT_HEAD(&head, n1, entries);
374 .\"O n2 = malloc(sizeof(struct entry)); /* Insert after. */
375 n2 = malloc(sizeof(struct entry)); /* ¸å¤í¤ËÁÞÆþ¤¹¤ë¡£*/
376 LIST_INSERT_AFTER(n1, n2, entries);
377 .\"O /* Forward traversal. */
379 for (np = head.lh_first; np != NULL; np = np\->entries.le_next)
382 .\"O while (head.lh_first != NULL) /* Delete. */
383 while (head.lh_first != NULL) /* ºï½ü¤¹¤ë¡£*/
384 LIST_REMOVE(head.lh_first, entries);
388 .\"O A tail queue is headed by a structure defined by the
391 ¥Æ¡¼¥ë¥¥å¡¼¤ÎÀèƬ¤Ë¤Ï
393 ¥Þ¥¯¥í¤ÇÄêµÁ¤µ¤ì¤ë¹½Â¤ÂΤ¬ÃÖ¤«¤ì¤ë¡£
394 .\"O This structure contains a pair of pointers,
395 .\"O one to the first element in the tail queue and the other to
396 .\"O the last element in the tail queue.
397 ¤³¤Î¹½Â¤ÂÎ¤Ï 1 ÁȤΥݥ¤¥ó¥¿¤ò´Þ¤ó¤Ç¤¤¤ë¡£
398 1 ¤Ä¤Ï¥Æ¡¼¥ë¥¥å¡¼¤ÎºÇ½é¤ÎÍ×ÁǤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ê¡¢
399 ¤â¤¦ 1 ¤Ä¤Ï¥Æ¡¼¥ë¥¥å¡¼¤ÎºÇ¸å¤ÎÍ×ÁǤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
400 .\"O The elements are doubly linked so that an arbitrary element can be
401 .\"O removed without traversing the tail queue.
402 Í×ÁÇ¤Ï 2 ½Å¤Ë¥ê¥ó¥¯¤µ¤ì¤Æ¤ª¤ê¡¢
403 Ǥ°Õ¤ÎÍ×ÁǤϥơ¼¥ë¥¥å¡¼¤òé¤é¤º¤Ëºï½ü¤Ç¤¤ë¡£
404 .\"O New elements can be added to the tail queue after an existing element,
405 .\"O at the head of the tail queue, or at the end of the tail queue.
406 ¿·¤·¤¤Í×ÁǤϴû¸¤ÎÍ×ÁǤθå¤Þ¤¿¤Ï¥Æ¡¼¥ë¥¥å¡¼¤ÎÀèƬ¤Þ¤¿¤ÏËöÈø¤ËÄɲäǤ¤ë¡£
409 .\"O structure is declared as follows:
411 ¹½Â¤ÂΤϰʲ¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
415 TAILQ_HEAD(HEADNAME, TYPE) head;
421 .\"O is the name of the structure to be defined, and
423 .\"O is the type of the elements to be linked into the tail queue.
426 ¤ÏÄêµÁ¤µ¤ì¤ë¹½Â¤ÂΤÎ̾Á°¤Ç¤¢¤ê¡¢
428 ¤Ï¥Æ¡¼¥ë¥¥å¡¼Æâ¤Ç¥ê¥ó¥¯¤µ¤ì¤ëÍ×ÁǤη¿¤Ç¤¢¤ë¡£
429 .\"O A pointer to the head of the tail queue can later be declared as:
430 ¥Æ¡¼¥ë¥¥å¡¼¤ÎÀèƬ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ï¡¢¤½¤Î¸å¤Ç¼¡¤Î¤è¤¦¤ËÀë¸À¤µ¤ì¤ë:
434 struct HEADNAME *headp;
442 .\"O are user selectable.)
447 ¤Ï¥æ¡¼¥¶¤¬ÁªÂò¤Ç¤¤ë¡£)
451 .\"O declares a structure that connects the elements in
455 ¤Ï¥Æ¡¼¥ë¥¥å¡¼¤ÎÍ×ÁǤòÀܳ¤¹¤ë¹½Â¤ÂΤòÀë¸À¤¹¤ë¡£
459 .\"O initializes the tail queue referenced by
465 ¤Ç»²¾È¤µ¤ì¤ë¥Æ¡¼¥ë¥¥å¡¼¤ò½é´ü²½¤¹¤ë¡£
468 .\"O .B TAILQ_INSERT_HEAD
469 .\"O inserts the new element
471 .\"O at the head of the tail queue.
476 ¤ò¥Æ¡¼¥ë¥¥å¡¼¤ÎÀèƬ¤ËÁÞÆþ¤¹¤ë¡£
479 .\"O .B TAILQ_INSERT_TAIL
480 .\"O inserts the new element
482 .\"O at the end of the tail queue.
487 ¤ò¥Æ¡¼¥ë¥¥å¡¼¤ÎËöÈø¤ËÁÞÆþ¤¹¤ë¡£
490 .\"O .B TAILQ_INSERT_AFTER
491 .\"O inserts the new element
493 .\"O after the element
496 .B TAILQ_INSERT_AFTER
505 .\"O removes the element
507 .\"O from the tail queue.
512 ¤ò¥Æ¡¼¥ë¥¥å¡¼¤«¤éºï½ü¤¹¤ë¡£
513 .\"O .SS Tail Queue Example
517 TAILQ_HEAD(tailhead, entry) head;
518 .\"O struct tailhead *headp; /* Tail queue head. */
519 struct tailhead *headp; /* ¥Æ¡¼¥ë¥¥å¡¼¤ÎÀèƬ¡£*/
522 .\"O TAILQ_ENTRY(entry) entries; /* Tail queue. */
523 TAILQ_ENTRY(entry) entries; /* ¥Æ¡¼¥ë¥¥å¡¼¡£*/
527 .\"O TAILQ_INIT(&head); /* Initialize the queue. */
528 TAILQ_INIT(&head); /* ¥¥å¡¼¤ò½é´ü²½¤¹¤ë¡£*/
530 .\"O n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
531 n1 = malloc(sizeof(struct entry)); /* ÀèƬ¤ËÁÞÆþ¤¹¤ë¡£*/
532 TAILQ_INSERT_HEAD(&head, n1, entries);
534 .\"O n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */
535 n1 = malloc(sizeof(struct entry)); /* ËöÈø¤ËÁÞÆþ¤¹¤ë¡£*/
536 TAILQ_INSERT_TAIL(&head, n1, entries);
538 .\"O n2 = malloc(sizeof(struct entry)); /* Insert after. */
539 n2 = malloc(sizeof(struct entry)); /* ¸å¤í¤ËÁÞÆþ¤¹¤ë¡£*/
540 TAILQ_INSERT_AFTER(&head, n1, n2, entries);
541 .\"O /* Forward traversal. */
543 for (np = head.tqh_first; np != NULL; np = np\->entries.tqe_next)
547 while (head.tqh_first != NULL)
548 TAILQ_REMOVE(&head, head.tqh_first, entries);
550 .\"O .SS Circular Queues
552 .\"O A circular queue is headed by a structure defined by the
557 ¥Þ¥¯¥í¤ÇÄêµÁ¤µ¤ì¤ë¹½Â¤ÂΤ¬ÃÖ¤«¤ì¤ë¡£
558 .\"O This structure contains a pair of pointers,
559 .\"O one to the first element in the circular queue and the other to the
560 .\"O last element in the circular queue.
561 ¤³¤Î¹½Â¤ÂÎ¤Ï 1 ÁȤΥݥ¤¥ó¥¿¤ò´Þ¤ó¤Ç¤¤¤ë¡£
562 1 ¤Ä¤Ï½Û´Ä¥¥å¡¼¤ÎºÇ½é¤ÎÍ×ÁǤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ê¡¢
563 ¤â¤¦ 1 ¤Ä¤Ï½Û´Ä¥¥å¡¼¤ÎºÇ¸å¤ÎÍ×ÁǤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
564 .\"O The elements are doubly linked so that an arbitrary element can be
565 .\"O removed without traversing the queue.
566 Í×ÁÇ¤Ï 2 ½Å¤Ë¥ê¥ó¥¯¤µ¤ì¤Æ¤ª¤ê¡¢
567 Ǥ°Õ¤ÎÍ×ÁǤϥ¥å¡¼¤òé¤é¤º¤Ëºï½ü¤Ç¤¤ë¡£
568 .\"O New elements can be added to the queue after an existing element,
569 .\"O before an existing element, at the head of the queue, or at the end
571 ¿·¤·¤¤Í×ÁǤϡ¢´û¸¤ÎÍ×ÁǤθå¤Þ¤¿¤ÏÁ°¡¢¤Þ¤¿¤Ï¥¥å¡¼¤ÎÀèƬ¤Þ¤¿¤ÏËöÈø¤ËÄɲäǤ¤ë¡£
574 .\"O structure is declared as follows:
576 ¹½Â¤ÂΤϰʲ¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
580 CIRCLEQ_HEAD(HEADNAME, TYPE) head;
586 .\"O is the name of the structure to be defined, and
588 .\"O is the type of the elements to be linked into the circular queue.
591 ¤ÏÄêµÁ¤µ¤ì¤ë¹½Â¤ÂΤÎ̾Á°¤Ç¤¢¤ê¡¢
593 ¤Ï½Û´Ä¥¥å¡¼Æâ¤Ç¥ê¥ó¥¯¤µ¤ì¤ëÍ×ÁǤη¿¤Ç¤¢¤ë¡£
594 .\"O A pointer to the head of the circular queue can later be declared as:
595 ½Û´Ä¥¥å¡¼¤ÎÀèƬ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ï¡¢¤½¤Î¸å¤Ç¼¡¤Î¤è¤¦¤ËÀë¸À¤µ¤ì¤ë:
599 struct HEADNAME *headp;
607 .\"O are user selectable.)
612 ¤Ï¥æ¡¼¥¶¤¬ÁªÂò¤Ç¤¤ë¡£)
615 .\"O .B CIRCLEQ_ENTRY
616 .\"O declares a structure that connects the elements in
617 .\"O the circular queue.
620 ¤Ï½Û´Ä¥¥å¡¼¤ÎÍ×ÁǤòÀܳ¤¹¤ë¹½Â¤ÂΤòÀë¸À¤¹¤ë¡£
624 .\"O initializes the circular queue referenced by
630 ¤Ç»²¾È¤µ¤ì¤ë½Û´Ä¥¥å¡¼¤ò½é´ü²½¤¹¤ë¡£
633 .\"O .B CIRCLEQ_INSERT_HEAD
634 .\"O inserts the new element
636 .\"O at the head of the circular queue.
638 .B CIRCLEQ_INSERT_HEAD
641 ¤ò½Û´Ä¥¥å¡¼¤ÎÀèƬ¤ËÁÞÆþ¤¹¤ë¡£
644 .\"O .B CIRCLEQ_INSERT_TAIL
645 .\"O inserts the new element
647 .\"O at the end of the circular queue.
649 .B CIRCLEQ_INSERT_TAIL
652 ¤ò½Û´Ä¥¥å¡¼¤ÎËöÈø¤ËÁÞÆþ¤¹¤ë¡£
655 .\"O .B CIRCLEQ_INSERT_AFTER
656 .\"O inserts the new element
658 .\"O after the element
661 .B CIRCLEQ_INSERT_AFTER
669 .\"O .B CIRCLEQ_INSERT_BEFORE
670 .\"O inserts the new element
672 .\"O before the element
675 .B CIRCLEQ_INSERT_AFTER
683 .\"O .B CIRCLEQ_REMOVE
684 .\"O removes the element
686 .\"O from the circular queue.
691 ¤ò½Û´Ä¥¥å¡¼¤«¤éºï½ü¤¹¤ë¡£
692 .\"O .SS Circular Queue Example
696 CIRCLEQ_HEAD(circleq, entry) head;
697 .\"O struct circleq *headp; /* Circular queue head. */
698 struct circleq *headp; /* ½Û´Ä¥¥å¡¼¤ÎÀèƬ¡£*/
701 .\"O CIRCLEQ_ENTRY(entry) entries; /* Circular queue. */
702 CIRCLEQ_ENTRY(entry) entries; /* ½Û´Ä¥¥å¡¼¡£*/
706 .\"O CIRCLEQ_INIT(&head); /* Initialize the circular queue. */
707 CIRCLEQ_INIT(&head); /* ½Û´Ä¥¥å¡¼¤ò½é´ü²½¤¹¤ë¡£*/
709 .\"O n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
710 n1 = malloc(sizeof(struct entry)); /* ÀèƬ¤ËÁÞÆþ¤¹¤ë¡£*/
711 CIRCLEQ_INSERT_HEAD(&head, n1, entries);
713 .\"O n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */
714 n1 = malloc(sizeof(struct entry)); /* ËöÈø¤ËÁÞÆþ¤¹¤ë¡£*/
715 CIRCLEQ_INSERT_TAIL(&head, n1, entries);
717 .\"O n2 = malloc(sizeof(struct entry)); /* Insert after. */
718 n2 = malloc(sizeof(struct entry)); /* ¸å¤í¤ËÁÞÆþ¤¹¤ë¡£*/
719 CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);
721 .\"O n2 = malloc(sizeof(struct entry)); /* Insert before. */
722 n2 = malloc(sizeof(struct entry)); /* Á°¤ËÁÞÆþ¤¹¤ë¡£*/
723 CIRCLEQ_INSERT_BEFORE(&head, n1, n2, entries);
724 .\"O /* Forward traversal. */
726 for (np = head.cqh_first; np != (void *)&head; np = np\->entries.cqe_next)
728 .\"O /* Reverse traversal. */
730 for (np = head.cqh_last; np != (void *)&head; np = np\->entries.cqe_prev)
734 while (head.cqh_first != (void *)&head)
735 CIRCLEQ_REMOVE(&head, head.cqh_first, entries);
737 .\"O .SH "CONFORMING TO"
739 .\"O Not in POSIX.1-2001.
740 .\"O Present on the BSDs.
742 .\"O queue functions first appeared in
744 POSIX.1-2001 ¤Ë¤Ï¤Ê¤¤¡£
746 queue ´Ø¿ô¤Ï 4.4BSD ¤Ç½é¤á¤ÆÅо줷¤¿¡£