source: rtems/cpukit/include/rtems/bsd/sys/queue.h @ cd9564e

4.104.114.84.95
Last change on this file since cd9564e was cd9564e, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/10/07 at 07:29:14

Include <rtems/bsd/sys/cdefs.h> instead of <sys/cdefs.h>.

  • Property mode set to 100644
File size: 18.6 KB
Line 
1/*
2 * Copyright (c) 1991, 1993
3 *      The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 *      @(#)queue.h     8.5 (Berkeley) 8/20/94
30 * $FreeBSD: src/sys/sys/queue.h,v 1.60 2005/03/02 21:33:29 joerg Exp $
31 */
32
33#ifndef _RTEMS_BSD_SYS_QUEUE_H
34#define _RTEMS_BSD_SYS_QUEUE_H
35
36#include <rtems/bsd/sys/cdefs.h>
37
38/*
39 * This file defines four types of data structures: singly-linked lists,
40 * singly-linked tail queues, lists and tail queues.
41 *
42 * A singly-linked list is headed by a single forward pointer. The elements
43 * are singly linked for minimum space and pointer manipulation overhead at
44 * the expense of O(n) removal for arbitrary elements. New elements can be
45 * added to the list after an existing element or at the head of the list.
46 * Elements being removed from the head of the list should use the explicit
47 * macro for this purpose for optimum efficiency. A singly-linked list may
48 * only be traversed in the forward direction.  Singly-linked lists are ideal
49 * for applications with large datasets and few or no removals or for
50 * implementing a LIFO queue.
51 *
52 * A singly-linked tail queue is headed by a pair of pointers, one to the
53 * head of the list and the other to the tail of the list. The elements are
54 * singly linked for minimum space and pointer manipulation overhead at the
55 * expense of O(n) removal for arbitrary elements. New elements can be added
56 * to the list after an existing element, at the head of the list, or at the
57 * end of the list. Elements being removed from the head of the tail queue
58 * should use the explicit macro for this purpose for optimum efficiency.
59 * A singly-linked tail queue may only be traversed in the forward direction.
60 * Singly-linked tail queues are ideal for applications with large datasets
61 * and few or no removals or for implementing a FIFO queue.
62 *
63 * A list is headed by a single forward pointer (or an array of forward
64 * pointers for a hash table header). The elements are doubly linked
65 * so that an arbitrary element can be removed without a need to
66 * traverse the list. New elements can be added to the list before
67 * or after an existing element or at the head of the list. A list
68 * may only be traversed in the forward direction.
69 *
70 * A tail queue is headed by a pair of pointers, one to the head of the
71 * list and the other to the tail of the list. The elements are doubly
72 * linked so that an arbitrary element can be removed without a need to
73 * traverse the list. New elements can be added to the list before or
74 * after an existing element, at the head of the list, or at the end of
75 * the list. A tail queue may be traversed in either direction.
76 *
77 * For details on the use of these macros, see the queue(3) manual page.
78 *
79 *
80 *                      SLIST   LIST    STAILQ  TAILQ
81 * _HEAD                +       +       +       +
82 * _HEAD_INITIALIZER    +       +       +       +
83 * _ENTRY               +       +       +       +
84 * _INIT                +       +       +       +
85 * _EMPTY               +       +       +       +
86 * _FIRST               +       +       +       +
87 * _NEXT                +       +       +       +
88 * _PREV                -       -       -       +
89 * _LAST                -       -       +       +
90 * _FOREACH             +       +       +       +
91 * _FOREACH_REVERSE     -       -       -       +
92 * _INSERT_HEAD         +       +       +       +
93 * _INSERT_BEFORE       -       +       -       +
94 * _INSERT_AFTER        +       +       +       +
95 * _INSERT_TAIL         -       -       +       +
96 * _CONCAT              -       -       +       +
97 * _REMOVE_HEAD         +       -       +       -
98 * _REMOVE              +       +       +       +
99 *
100 */
101#define QUEUE_MACRO_DEBUG 0
102#if QUEUE_MACRO_DEBUG
103/* Store the last 2 places the queue element or head was altered */
104struct qm_trace {
105        char * lastfile;
106        int lastline;
107        char * prevfile;
108        int prevline;
109};
110
111#define TRACEBUF        struct qm_trace trace;
112#define TRASHIT(x)      do {(x) = (void *)-1;} while (0)
113
114#define QMD_TRACE_HEAD(head) do {                                       \
115        (head)->trace.prevline = (head)->trace.lastline;                \
116        (head)->trace.prevfile = (head)->trace.lastfile;                \
117        (head)->trace.lastline = __LINE__;                              \
118        (head)->trace.lastfile = __FILE__;                              \
119} while (0)
120
121#define QMD_TRACE_ELEM(elem) do {                                       \
122        (elem)->trace.prevline = (elem)->trace.lastline;                \
123        (elem)->trace.prevfile = (elem)->trace.lastfile;                \
124        (elem)->trace.lastline = __LINE__;                              \
125        (elem)->trace.lastfile = __FILE__;                              \
126} while (0)
127
128#else
129#define QMD_TRACE_ELEM(elem)
130#define QMD_TRACE_HEAD(head)
131#define TRACEBUF
132#define TRASHIT(x)
133#endif  /* QUEUE_MACRO_DEBUG */
134
135/*
136 * Singly-linked List declarations.
137 */
138#define SLIST_HEAD(name, type)                                          \
139struct name {                                                           \
140        struct type *slh_first; /* first element */                     \
141}
142
143#define SLIST_HEAD_INITIALIZER(head)                                    \
144        { NULL }
145 
146#define SLIST_ENTRY(type)                                               \
147struct {                                                                \
148        struct type *sle_next;  /* next element */                      \
149}
150 
151/*
152 * Singly-linked List functions.
153 */
154#define SLIST_EMPTY(head)       ((head)->slh_first == NULL)
155
156#define SLIST_FIRST(head)       ((head)->slh_first)
157
158#define SLIST_FOREACH(var, head, field)                                 \
159        for ((var) = SLIST_FIRST((head));                               \
160            (var);                                                      \
161            (var) = SLIST_NEXT((var), field))
162
163#define SLIST_FOREACH_PREVPTR(var, varp, head, field)                   \
164        for ((varp) = &SLIST_FIRST((head));                             \
165            ((var) = *(varp)) != NULL;                                  \
166            (varp) = &SLIST_NEXT((var), field))
167
168#define SLIST_INIT(head) do {                                           \
169        SLIST_FIRST((head)) = NULL;                                     \
170} while (0)
171
172#define SLIST_INSERT_AFTER(slistelm, elm, field) do {                   \
173        SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);       \
174        SLIST_NEXT((slistelm), field) = (elm);                          \
175} while (0)
176
177#define SLIST_INSERT_HEAD(head, elm, field) do {                        \
178        SLIST_NEXT((elm), field) = SLIST_FIRST((head));                 \
179        SLIST_FIRST((head)) = (elm);                                    \
180} while (0)
181
182#define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
183
184#define SLIST_REMOVE(head, elm, type, field) do {                       \
185        if (SLIST_FIRST((head)) == (elm)) {                             \
186                SLIST_REMOVE_HEAD((head), field);                       \
187        }                                                               \
188        else {                                                          \
189                struct type *curelm = SLIST_FIRST((head));              \
190                while (SLIST_NEXT(curelm, field) != (elm))              \
191                        curelm = SLIST_NEXT(curelm, field);             \
192                SLIST_NEXT(curelm, field) =                             \
193                    SLIST_NEXT(SLIST_NEXT(curelm, field), field);       \
194        }                                                               \
195} while (0)
196
197#define SLIST_REMOVE_HEAD(head, field) do {                             \
198        SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);   \
199} while (0)
200
201/*
202 * Singly-linked Tail queue declarations.
203 */
204#define STAILQ_HEAD(name, type)                                         \
205struct name {                                                           \
206        struct type *stqh_first;/* first element */                     \
207        struct type **stqh_last;/* addr of last next element */         \
208}
209
210#define STAILQ_HEAD_INITIALIZER(head)                                   \
211        { NULL, &(head).stqh_first }
212
213#define STAILQ_ENTRY(type)                                              \
214struct {                                                                \
215        struct type *stqe_next; /* next element */                      \
216}
217
218/*
219 * Singly-linked Tail queue functions.
220 */
221#define STAILQ_CONCAT(head1, head2) do {                                \
222        if (!STAILQ_EMPTY((head2))) {                                   \
223                *(head1)->stqh_last = (head2)->stqh_first;              \
224                (head1)->stqh_last = (head2)->stqh_last;                \
225                STAILQ_INIT((head2));                                   \
226        }                                                               \
227} while (0)
228
229#define STAILQ_EMPTY(head)      ((head)->stqh_first == NULL)
230
231#define STAILQ_FIRST(head)      ((head)->stqh_first)
232
233#define STAILQ_FOREACH(var, head, field)                                \
234        for((var) = STAILQ_FIRST((head));                               \
235           (var);                                                       \
236           (var) = STAILQ_NEXT((var), field))
237
238#define STAILQ_INIT(head) do {                                          \
239        STAILQ_FIRST((head)) = NULL;                                    \
240        (head)->stqh_last = &STAILQ_FIRST((head));                      \
241} while (0)
242
243#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {               \
244        if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
245                (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
246        STAILQ_NEXT((tqelm), field) = (elm);                            \
247} while (0)
248
249#define STAILQ_INSERT_HEAD(head, elm, field) do {                       \
250        if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
251                (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
252        STAILQ_FIRST((head)) = (elm);                                   \
253} while (0)
254
255#define STAILQ_INSERT_TAIL(head, elm, field) do {                       \
256        STAILQ_NEXT((elm), field) = NULL;                               \
257        *(head)->stqh_last = (elm);                                     \
258        (head)->stqh_last = &STAILQ_NEXT((elm), field);                 \
259} while (0)
260
261#define STAILQ_LAST(head, type, field)                                  \
262        (STAILQ_EMPTY((head)) ?                                         \
263                NULL :                                                  \
264                ((struct type *)                                        \
265                ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
266
267#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
268
269#define STAILQ_REMOVE(head, elm, type, field) do {                      \
270        if (STAILQ_FIRST((head)) == (elm)) {                            \
271                STAILQ_REMOVE_HEAD((head), field);                      \
272        }                                                               \
273        else {                                                          \
274                struct type *curelm = STAILQ_FIRST((head));             \
275                while (STAILQ_NEXT(curelm, field) != (elm))             \
276                        curelm = STAILQ_NEXT(curelm, field);            \
277                if ((STAILQ_NEXT(curelm, field) =                       \
278                     STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
279                        (head)->stqh_last = &STAILQ_NEXT((curelm), field);\
280        }                                                               \
281} while (0)
282
283#define STAILQ_REMOVE_HEAD(head, field) do {                            \
284        if ((STAILQ_FIRST((head)) =                                     \
285             STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)         \
286                (head)->stqh_last = &STAILQ_FIRST((head));              \
287} while (0)
288
289#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do {                 \
290        if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \
291                (head)->stqh_last = &STAILQ_FIRST((head));              \
292} while (0)
293
294/*
295 * List declarations.
296 */
297#define LIST_HEAD(name, type)                                           \
298struct name {                                                           \
299        struct type *lh_first;  /* first element */                     \
300}
301
302#define LIST_HEAD_INITIALIZER(head)                                     \
303        { NULL }
304
305#define LIST_ENTRY(type)                                                \
306struct {                                                                \
307        struct type *le_next;   /* next element */                      \
308        struct type **le_prev;  /* address of previous next element */  \
309}
310
311/*
312 * List functions.
313 */
314
315#define LIST_EMPTY(head)        ((head)->lh_first == NULL)
316
317#define LIST_FIRST(head)        ((head)->lh_first)
318
319#define LIST_FOREACH(var, head, field)                                  \
320        for ((var) = LIST_FIRST((head));                                \
321            (var);                                                      \
322            (var) = LIST_NEXT((var), field))
323
324#define LIST_INIT(head) do {                                            \
325        LIST_FIRST((head)) = NULL;                                      \
326} while (0)
327
328#define LIST_INSERT_AFTER(listelm, elm, field) do {                     \
329        if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
330                LIST_NEXT((listelm), field)->field.le_prev =            \
331                    &LIST_NEXT((elm), field);                           \
332        LIST_NEXT((listelm), field) = (elm);                            \
333        (elm)->field.le_prev = &LIST_NEXT((listelm), field);            \
334} while (0)
335
336#define LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
337        (elm)->field.le_prev = (listelm)->field.le_prev;                \
338        LIST_NEXT((elm), field) = (listelm);                            \
339        *(listelm)->field.le_prev = (elm);                              \
340        (listelm)->field.le_prev = &LIST_NEXT((elm), field);            \
341} while (0)
342
343#define LIST_INSERT_HEAD(head, elm, field) do {                         \
344        if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)     \
345                LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
346        LIST_FIRST((head)) = (elm);                                     \
347        (elm)->field.le_prev = &LIST_FIRST((head));                     \
348} while (0)
349
350#define LIST_NEXT(elm, field)   ((elm)->field.le_next)
351
352#define LIST_REMOVE(elm, field) do {                                    \
353        if (LIST_NEXT((elm), field) != NULL)                            \
354                LIST_NEXT((elm), field)->field.le_prev =                \
355                    (elm)->field.le_prev;                               \
356        *(elm)->field.le_prev = LIST_NEXT((elm), field);                \
357} while (0)
358
359/*
360 * Tail queue declarations.
361 */
362#define TAILQ_HEAD(name, type)                                          \
363struct name {                                                           \
364        struct type *tqh_first; /* first element */                     \
365        struct type **tqh_last; /* addr of last next element */         \
366        TRACEBUF                                                        \
367}
368
369#define TAILQ_HEAD_INITIALIZER(head)                                    \
370        { NULL, &(head).tqh_first }
371
372#define TAILQ_ENTRY(type)                                               \
373struct {                                                                \
374        struct type *tqe_next;  /* next element */                      \
375        struct type **tqe_prev; /* address of previous next element */  \
376        TRACEBUF                                                        \
377}
378
379/*
380 * Tail queue functions.
381 */
382#define TAILQ_CONCAT(head1, head2, field) do {                          \
383        if (!TAILQ_EMPTY(head2)) {                                      \
384                *(head1)->tqh_last = (head2)->tqh_first;                \
385                (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
386                (head1)->tqh_last = (head2)->tqh_last;                  \
387                TAILQ_INIT((head2));                                    \
388                QMD_TRACE_HEAD(head);                                   \
389                QMD_TRACE_HEAD(head2);                                  \
390        }                                                               \
391} while (0)
392
393#define TAILQ_EMPTY(head)       ((head)->tqh_first == NULL)
394
395#define TAILQ_FIRST(head)       ((head)->tqh_first)
396
397#define TAILQ_FOREACH(var, head, field)                                 \
398        for ((var) = TAILQ_FIRST((head));                               \
399            (var);                                                      \
400            (var) = TAILQ_NEXT((var), field))
401
402#define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
403        for ((var) = TAILQ_LAST((head), headname);                      \
404            (var);                                                      \
405            (var) = TAILQ_PREV((var), headname, field))
406
407#define TAILQ_INIT(head) do {                                           \
408        TAILQ_FIRST((head)) = NULL;                                     \
409        (head)->tqh_last = &TAILQ_FIRST((head));                        \
410        QMD_TRACE_HEAD(head);                                           \
411} while (0)
412
413#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
414        if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
415                TAILQ_NEXT((elm), field)->field.tqe_prev =              \
416                    &TAILQ_NEXT((elm), field);                          \
417        else {                                                          \
418                (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
419                QMD_TRACE_HEAD(head);                                   \
420        }                                                               \
421        TAILQ_NEXT((listelm), field) = (elm);                           \
422        (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);          \
423        QMD_TRACE_ELEM(&(elm)->field);                                  \
424        QMD_TRACE_ELEM(&listelm->field);                                \
425} while (0)
426
427#define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
428        (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
429        TAILQ_NEXT((elm), field) = (listelm);                           \
430        *(listelm)->field.tqe_prev = (elm);                             \
431        (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);          \
432        QMD_TRACE_ELEM(&(elm)->field);                                  \
433        QMD_TRACE_ELEM(&listelm->field);                                \
434} while (0)
435
436#define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
437        if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)   \
438                TAILQ_FIRST((head))->field.tqe_prev =                   \
439                    &TAILQ_NEXT((elm), field);                          \
440        else                                                            \
441                (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
442        TAILQ_FIRST((head)) = (elm);                                    \
443        (elm)->field.tqe_prev = &TAILQ_FIRST((head));                   \
444        QMD_TRACE_HEAD(head);                                           \
445        QMD_TRACE_ELEM(&(elm)->field);                                  \
446} while (0)
447
448#define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
449        TAILQ_NEXT((elm), field) = NULL;                                \
450        (elm)->field.tqe_prev = (head)->tqh_last;                       \
451        *(head)->tqh_last = (elm);                                      \
452        (head)->tqh_last = &TAILQ_NEXT((elm), field);                   \
453        QMD_TRACE_HEAD(head);                                           \
454        QMD_TRACE_ELEM(&(elm)->field);                                  \
455} while (0)
456
457#define TAILQ_LAST(head, headname)                                      \
458        (*(((struct headname *)((head)->tqh_last))->tqh_last))
459
460#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
461
462#define TAILQ_PREV(elm, headname, field)                                \
463        (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
464
465#define TAILQ_REMOVE(head, elm, field) do {                             \
466        if ((TAILQ_NEXT((elm), field)) != NULL)                         \
467                TAILQ_NEXT((elm), field)->field.tqe_prev =              \
468                    (elm)->field.tqe_prev;                              \
469        else {                                                          \
470                (head)->tqh_last = (elm)->field.tqe_prev;               \
471                QMD_TRACE_HEAD(head);                                   \
472        }                                                               \
473        *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);              \
474        TRASHIT((elm)->field.tqe_next);                                 \
475        TRASHIT((elm)->field.tqe_prev);                                 \
476        QMD_TRACE_ELEM(&(elm)->field);                                  \
477} while (0)
478
479
480/*
481 * Circular queue definitions.
482 */
483#define CIRCLEQ_HEAD(name, type)                                        \
484struct name {                                                           \
485        struct type *cqh_first;         /* first element */             \
486        struct type *cqh_last;          /* last element */              \
487}
488
489#define CIRCLEQ_ENTRY(type)                                             \
490struct {                                                                \
491        struct type *cqe_next;          /* next element */              \
492        struct type *cqe_prev;          /* previous element */          \
493}
494
495/*
496 * Circular queue functions.
497 */
498#define CIRCLEQ_INIT(head) {                                            \
499        (head)->cqh_first = (void *)(head);                             \
500        (head)->cqh_last = (void *)(head);                              \
501}
502
503#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) {               \
504        (elm)->field.cqe_next = (listelm)->field.cqe_next;              \
505        (elm)->field.cqe_prev = (listelm);                              \
506        if ((listelm)->field.cqe_next == (void *)(head))                \
507                (head)->cqh_last = (elm);                               \
508        else                                                            \
509                (listelm)->field.cqe_next->field.cqe_prev = (elm);      \
510        (listelm)->field.cqe_next = (elm);                              \
511}
512
513#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) {              \
514        (elm)->field.cqe_next = (listelm);                              \
515        (elm)->field.cqe_prev = (listelm)->field.cqe_prev;              \
516        if ((listelm)->field.cqe_prev == (void *)(head))                \
517                (head)->cqh_first = (elm);                              \
518        else                                                            \
519                (listelm)->field.cqe_prev->field.cqe_next = (elm);      \
520        (listelm)->field.cqe_prev = (elm);                              \
521}
522
523#define CIRCLEQ_INSERT_HEAD(head, elm, field) {                         \
524        (elm)->field.cqe_next = (head)->cqh_first;                      \
525        (elm)->field.cqe_prev = (void *)(head);                         \
526        if ((head)->cqh_last == (void *)(head))                         \
527                (head)->cqh_last = (elm);                               \
528        else                                                            \
529                (head)->cqh_first->field.cqe_prev = (elm);              \
530        (head)->cqh_first = (elm);                                      \
531}
532
533#define CIRCLEQ_INSERT_TAIL(head, elm, field) {                         \
534        (elm)->field.cqe_next = (void *)(head);                         \
535        (elm)->field.cqe_prev = (head)->cqh_last;                       \
536        if ((head)->cqh_first == (void *)(head))                        \
537                (head)->cqh_first = (elm);                              \
538        else                                                            \
539                (head)->cqh_last->field.cqe_next = (elm);               \
540        (head)->cqh_last = (elm);                                       \
541}
542
543#define CIRCLEQ_REMOVE(head, elm, field) {                              \
544        if ((elm)->field.cqe_next == (void *)(head))                    \
545                (head)->cqh_last = (elm)->field.cqe_prev;               \
546        else                                                            \
547                (elm)->field.cqe_next->field.cqe_prev =                 \
548                    (elm)->field.cqe_prev;                              \
549        if ((elm)->field.cqe_prev == (void *)(head))                    \
550                (head)->cqh_first = (elm)->field.cqe_next;              \
551        else                                                            \
552                (elm)->field.cqe_prev->field.cqe_next =                 \
553                    (elm)->field.cqe_next;                              \
554}
555
556#ifdef _KERNEL
557
558/*
559 * XXX insque() and remque() are an old way of handling certain queues.
560 * They bogusly assumes that all queue heads look alike.
561 */
562
563
564#ifdef  __GNUC__
565
566struct quehead {
567    struct quehead *qh_link;
568    struct quehead *qh_rlink;
569};
570
571static __inline void
572insque(void *a, void *b)
573{
574        struct quehead *element = (struct quehead *)a,
575                 *head = (struct quehead *)b;
576
577        element->qh_link = head->qh_link;
578        element->qh_rlink = head;
579        head->qh_link = element;
580        element->qh_link->qh_rlink = element;
581}
582
583static __inline void
584remque(void *a)
585{
586        struct quehead *element = (struct quehead *)a;
587
588        element->qh_link->qh_rlink = element->qh_rlink;
589        element->qh_rlink->qh_link = element->qh_link;
590        element->qh_rlink = 0;
591}
592
593#else /* !__GNUC__ */
594
595void    insque(void *a, void *b);
596void    remque(void *a);
597
598#endif /* __GNUC__ */
599
600#endif /* _KERNEL */
601
602#endif /* !_RTEMS_BSD_SYS_QUEUE_H */
Note: See TracBrowser for help on using the repository browser.