OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [remove_cycle/] [agony/] [queue.h] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
/*      $NetBSD: queue.h,v 1.41 2005/05/29 21:14:40 christos Exp $      */
2
/*      $Id: queue.h,v 1.3 2005-12-15 13:03:30 pooka Exp $      */
3
 
4
/*
5
 * Copyright (c) 1991, 1993
6
 *      The Regents of the University of California.  All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. 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.
19
 *
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
30
 * SUCH DAMAGE.
31
 *
32
 *      @(#)queue.h     8.5 (Berkeley) 8/20/94
33
 */
34
 
35
#ifndef QUEUE__SYS_QUEUE_H_
36
#define QUEUE__SYS_QUEUE_H_
37
 
38
/*
39
 * This file defines five types of data structures: singly-linked lists,
40
 * lists, simple queues, tail queues, and circular queues.
41
 *
42
 * A singly-linked list is headed by a single forward pointer. The
43
 * elements are singly linked for minimum space and pointer manipulation
44
 * overhead at the expense of O(n) removal for arbitrary elements. New
45
 * elements can be added to the list after an existing element or at the
46
 * head of the list.  Elements being removed from the head of the list
47
 * should use the explicit macro for this purpose for optimum
48
 * efficiency. A singly-linked list may only be traversed in the forward
49
 * direction.  Singly-linked lists are ideal for applications with large
50
 * datasets and few or no removals or for implementing a LIFO queue.
51
 *
52
 * A list is headed by a single forward pointer (or an array of forward
53
 * pointers for a hash table header). The elements are doubly linked
54
 * so that an arbitrary element can be removed without a need to
55
 * traverse the list. New elements can be added to the list before
56
 * or after an existing element or at the head of the list. A list
57
 * may only be traversed in the forward direction.
58
 *
59
 * A simple queue is headed by a pair of pointers, one the head of the
60
 * list and the other to the tail of the list. The elements are singly
61
 * linked to save space, so only elements can only be removed from the
62
 * head of the list. New elements can be added to the list after
63
 * an existing element, at the head of the list, or at the end of the
64
 * list. A simple queue may only be traversed in the forward direction.
65
 *
66
 * A tail queue is headed by a pair of pointers, one to the head of the
67
 * list and the other to the tail of the list. The elements are doubly
68
 * linked so that an arbitrary element can be removed without a need to
69
 * traverse the list. New elements can be added to the list before or
70
 * after an existing element, at the head of the list, or at the end of
71
 * the list. A tail queue may be traversed in either direction.
72
 *
73
 * A circle queue is headed by a pair of pointers, one to the head of the
74
 * list and the other to the tail of the list. The elements are doubly
75
 * linked so that an arbitrary element can be removed without a need to
76
 * traverse the list. New elements can be added to the list before or after
77
 * an existing element, at the head of the list, or at the end of the list.
78
 * A circle queue may be traversed in either direction, but has a more
79
 * complex end of list detection.
80
 *
81
 * For details on the use of these macros, see the queue(3) manual page.
82
 */
83
 
84
/*
85
 * List definitions.
86
 */
87
#define LIST_HEAD(name, type)                                           \
88
struct name {                                                           \
89
        struct type *lh_first;  /* first element */                     \
90
}
91
 
92
#define LIST_HEAD_INITIALIZER(head)                                     \
93
        { NULL }
94
 
95
#define LIST_ENTRY(type)                                                \
96
struct {                                                                \
97
        struct type *le_next;   /* next element */                      \
98
        struct type **le_prev;  /* address of previous next element */  \
99
}
100
 
101
/*
102
 * List functions.
103
 */
104
#if defined(_KERNEL) && defined(QUEUEDEBUG)
105
#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field)                   \
106
        if ((head)->lh_first &&                                         \
107
            (head)->lh_first->field.le_prev != &(head)->lh_first)       \
108
                panic("LIST_INSERT_HEAD %p %s:%d", (head), __FILE__, __LINE__);
109
#define QUEUEDEBUG_LIST_OP(elm, field)                                  \
110
        if ((elm)->field.le_next &&                                     \
111
            (elm)->field.le_next->field.le_prev !=                      \
112
            &(elm)->field.le_next)                                      \
113
                panic("LIST_* forw %p %s:%d", (elm), __FILE__, __LINE__);\
114
        if (*(elm)->field.le_prev != (elm))                             \
115
                panic("LIST_* back %p %s:%d", (elm), __FILE__, __LINE__);
116
#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field)                          \
117
        (elm)->field.le_next = (void *)1L;                              \
118
        (elm)->field.le_prev = (void *)1L;
119
#else
120
#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field)
121
#define QUEUEDEBUG_LIST_OP(elm, field)
122
#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field)
123
#endif
124
 
125
#define LIST_INIT(head) do {                                            \
126
        (head)->lh_first = NULL;                                        \
127
} while (/*CONSTCOND*/0)
128
 
129
#define LIST_INSERT_AFTER(listelm, elm, field) do {                     \
130
        QUEUEDEBUG_LIST_OP((listelm), field)                            \
131
        if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)  \
132
                (listelm)->field.le_next->field.le_prev =               \
133
                    &(elm)->field.le_next;                              \
134
        (listelm)->field.le_next = (elm);                               \
135
        (elm)->field.le_prev = &(listelm)->field.le_next;               \
136
} while (/*CONSTCOND*/0)
137
 
138
#define LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
139
        QUEUEDEBUG_LIST_OP((listelm), field)                            \
140
        (elm)->field.le_prev = (listelm)->field.le_prev;                \
141
        (elm)->field.le_next = (listelm);                               \
142
        *(listelm)->field.le_prev = (elm);                              \
143
        (listelm)->field.le_prev = &(elm)->field.le_next;               \
144
} while (/*CONSTCOND*/0)
145
 
146
#define LIST_INSERT_HEAD(head, elm, field) do {                         \
147
        QUEUEDEBUG_LIST_INSERT_HEAD((head), (elm), field)               \
148
        if (((elm)->field.le_next = (head)->lh_first) != NULL)          \
149
                (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
150
        (head)->lh_first = (elm);                                       \
151
        (elm)->field.le_prev = &(head)->lh_first;                       \
152
} while (/*CONSTCOND*/0)
153
 
154
#define LIST_REMOVE(elm, field) do {                                    \
155
        QUEUEDEBUG_LIST_OP((elm), field)                                \
156
        if ((elm)->field.le_next != NULL)                               \
157
                (elm)->field.le_next->field.le_prev =                   \
158
                    (elm)->field.le_prev;                               \
159
        *(elm)->field.le_prev = (elm)->field.le_next;                   \
160
        QUEUEDEBUG_LIST_POSTREMOVE((elm), field)                        \
161
} while (/*CONSTCOND*/0)
162
 
163
#define LIST_FOREACH(var, head, field)                                  \
164
        for ((var) = ((head)->lh_first);                                \
165
                (var);                                                  \
166
                (var) = ((var)->field.le_next))
167
 
168
/*
169
 * List access methods.
170
 */
171
#define LIST_EMPTY(head)                ((head)->lh_first == NULL)
172
#define LIST_FIRST(head)                ((head)->lh_first)
173
#define LIST_NEXT(elm, field)           ((elm)->field.le_next)
174
 
175
 
176
/*
177
 * Singly-linked List definitions.
178
 */
179
#define SLIST_HEAD(name, type)                                          \
180
struct name {                                                           \
181
        struct type *slh_first; /* first element */                     \
182
}
183
 
184
#define SLIST_HEAD_INITIALIZER(head)                                    \
185
        { NULL }
186
 
187
#define SLIST_ENTRY(type)                                               \
188
struct {                                                                \
189
        struct type *sle_next;  /* next element */                      \
190
}
191
 
192
/*
193
 * Singly-linked List functions.
194
 */
195
#define SLIST_INIT(head) do {                                           \
196
        (head)->slh_first = NULL;                                       \
197
} while (/*CONSTCOND*/0)
198
 
199
#define SLIST_INSERT_AFTER(slistelm, elm, field) do {                   \
200
        (elm)->field.sle_next = (slistelm)->field.sle_next;             \
201
        (slistelm)->field.sle_next = (elm);                             \
202
} while (/*CONSTCOND*/0)
203
 
204
#define SLIST_INSERT_HEAD(head, elm, field) do {                        \
205
        (elm)->field.sle_next = (head)->slh_first;                      \
206
        (head)->slh_first = (elm);                                      \
207
} while (/*CONSTCOND*/0)
208
 
209
#define SLIST_REMOVE_HEAD(head, field) do {                             \
210
        (head)->slh_first = (head)->slh_first->field.sle_next;          \
211
} while (/*CONSTCOND*/0)
212
 
213
#define SLIST_REMOVE(head, elm, type, field) do {                       \
214
        if ((head)->slh_first == (elm)) {                               \
215
                SLIST_REMOVE_HEAD((head), field);                       \
216
        }                                                               \
217
        else {                                                          \
218
                struct type *curelm = (head)->slh_first;                \
219
                while(curelm->field.sle_next != (elm))                  \
220
                        curelm = curelm->field.sle_next;                \
221
                curelm->field.sle_next =                                \
222
                    curelm->field.sle_next->field.sle_next;             \
223
        }                                                               \
224
} while (/*CONSTCOND*/0)
225
 
226
#define SLIST_FOREACH(var, head, field)                                 \
227
        for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
228
 
229
/*
230
 * Singly-linked List access methods.
231
 */
232
#define SLIST_EMPTY(head)       ((head)->slh_first == NULL)
233
#define SLIST_FIRST(head)       ((head)->slh_first)
234
#define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
235
 
236
 
237
/*
238
 * Singly-linked Tail queue declarations.
239
 */
240
#define STAILQ_HEAD(name, type)                                 \
241
struct name {                                                           \
242
        struct type *stqh_first;        /* first element */                     \
243
        struct type **stqh_last;        /* addr of last next element */         \
244
}
245
 
246
#define STAILQ_HEAD_INITIALIZER(head)                                   \
247
        { NULL, &(head).stqh_first }
248
 
249
#define STAILQ_ENTRY(type)                                              \
250
struct {                                                                \
251
        struct type *stqe_next; /* next element */                      \
252
}
253
 
254
/*
255
 * Singly-linked Tail queue functions.
256
 */
257
#define STAILQ_INIT(head) do {                                          \
258
        (head)->stqh_first = NULL;                                      \
259
        (head)->stqh_last = &(head)->stqh_first;                                \
260
} while (/*CONSTCOND*/0)
261
 
262
#define STAILQ_INSERT_HEAD(head, elm, field) do {                       \
263
        if (((elm)->field.stqe_next = (head)->stqh_first) == NULL)      \
264
                (head)->stqh_last = &(elm)->field.stqe_next;            \
265
        (head)->stqh_first = (elm);                                     \
266
} while (/*CONSTCOND*/0)
267
 
268
#define STAILQ_INSERT_TAIL(head, elm, field) do {                       \
269
        (elm)->field.stqe_next = NULL;                                  \
270
        *(head)->stqh_last = (elm);                                     \
271
        (head)->stqh_last = &(elm)->field.stqe_next;                    \
272
} while (/*CONSTCOND*/0)
273
 
274
#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do {             \
275
        if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
276
                (head)->stqh_last = &(elm)->field.stqe_next;            \
277
        (listelm)->field.stqe_next = (elm);                             \
278
} while (/*CONSTCOND*/0)
279
 
280
#define STAILQ_REMOVE_HEAD(head, field) do {                            \
281
        if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
282
                (head)->stqh_last = &(head)->stqh_first;                        \
283
} while (/*CONSTCOND*/0)
284
 
285
#define STAILQ_REMOVE(head, elm, type, field) do {                      \
286
        if ((head)->stqh_first == (elm)) {                              \
287
                STAILQ_REMOVE_HEAD((head), field);                      \
288
        } else {                                                        \
289
                struct type *curelm = (head)->stqh_first;               \
290
                while (curelm->field.stqe_next != (elm))                        \
291
                        curelm = curelm->field.stqe_next;               \
292
                if ((curelm->field.stqe_next =                          \
293
                        curelm->field.stqe_next->field.stqe_next) == NULL) \
294
                            (head)->stqh_last = &(curelm)->field.stqe_next; \
295
        }                                                               \
296
} while (/*CONSTCOND*/0)
297
 
298
#define STAILQ_FOREACH(var, head, field)                                \
299
        for ((var) = ((head)->stqh_first);                              \
300
                (var);                                                  \
301
                (var) = ((var)->field.stqe_next))
302
 
303
/*
304
 * Singly-linked Tail queue access methods.
305
 */
306
#define STAILQ_EMPTY(head)      ((head)->stqh_first == NULL)
307
#define STAILQ_FIRST(head)      ((head)->stqh_first)
308
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
309
 
310
 
311
/*
312
 * Simple queue definitions.
313
 */
314
#define SIMPLEQ_HEAD(name, type)                                        \
315
struct name {                                                           \
316
        struct type *sqh_first; /* first element */                     \
317
        struct type **sqh_last; /* addr of last next element */         \
318
}
319
 
320
#define SIMPLEQ_HEAD_INITIALIZER(head)                                  \
321
        { NULL, &(head).sqh_first }
322
 
323
#define SIMPLEQ_ENTRY(type)                                             \
324
struct {                                                                \
325
        struct type *sqe_next;  /* next element */                      \
326
}
327
 
328
/*
329
 * Simple queue functions.
330
 */
331
#define SIMPLEQ_INIT(head) do {                                         \
332
        (head)->sqh_first = NULL;                                       \
333
        (head)->sqh_last = &(head)->sqh_first;                          \
334
} while (/*CONSTCOND*/0)
335
 
336
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do {                      \
337
        if (((elm)->field.sqe_next = (head)->sqh_first) == NULL)        \
338
                (head)->sqh_last = &(elm)->field.sqe_next;              \
339
        (head)->sqh_first = (elm);                                      \
340
} while (/*CONSTCOND*/0)
341
 
342
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do {                      \
343
        (elm)->field.sqe_next = NULL;                                   \
344
        *(head)->sqh_last = (elm);                                      \
345
        (head)->sqh_last = &(elm)->field.sqe_next;                      \
346
} while (/*CONSTCOND*/0)
347
 
348
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {            \
349
        if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
350
                (head)->sqh_last = &(elm)->field.sqe_next;              \
351
        (listelm)->field.sqe_next = (elm);                              \
352
} while (/*CONSTCOND*/0)
353
 
354
#define SIMPLEQ_REMOVE_HEAD(head, field) do {                           \
355
        if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
356
                (head)->sqh_last = &(head)->sqh_first;                  \
357
} while (/*CONSTCOND*/0)
358
 
359
#define SIMPLEQ_REMOVE(head, elm, type, field) do {                     \
360
        if ((head)->sqh_first == (elm)) {                               \
361
                SIMPLEQ_REMOVE_HEAD((head), field);                     \
362
        } else {                                                        \
363
                struct type *curelm = (head)->sqh_first;                \
364
                while (curelm->field.sqe_next != (elm))                 \
365
                        curelm = curelm->field.sqe_next;                \
366
                if ((curelm->field.sqe_next =                           \
367
                        curelm->field.sqe_next->field.sqe_next) == NULL) \
368
                            (head)->sqh_last = &(curelm)->field.sqe_next; \
369
        }                                                               \
370
} while (/*CONSTCOND*/0)
371
 
372
#define SIMPLEQ_FOREACH(var, head, field)                               \
373
        for ((var) = ((head)->sqh_first);                               \
374
                (var);                                                  \
375
                (var) = ((var)->field.sqe_next))
376
 
377
/*
378
 * Simple queue access methods.
379
 */
380
#define SIMPLEQ_EMPTY(head)             ((head)->sqh_first == NULL)
381
#define SIMPLEQ_FIRST(head)             ((head)->sqh_first)
382
#define SIMPLEQ_NEXT(elm, field)        ((elm)->field.sqe_next)
383
 
384
 
385
/*
386
 * Tail queue definitions.
387
 */
388
#define TAILQ_HEAD(name, type)                                          \
389
struct name {                                                           \
390
        struct type *tqh_first;         /* first element */             \
391
        struct type **tqh_last;         /* addr of last next element */ \
392
}
393
 
394
#define TAILQ_HEAD_INITIALIZER(head)                                    \
395
        { NULL, &(head).tqh_first }
396
 
397
#define TAILQ_ENTRY(type)                                               \
398
struct {                                                                \
399
        struct type *tqe_next;  /* next element */                      \
400
        struct type **tqe_prev; /* address of previous next element */  \
401
}
402
 
403
/*
404
 * Tail queue functions.
405
 */
406
#if defined(_KERNEL) && defined(QUEUEDEBUG)
407
#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field)                  \
408
        if ((head)->tqh_first &&                                        \
409
            (head)->tqh_first->field.tqe_prev != &(head)->tqh_first)    \
410
                panic("TAILQ_INSERT_HEAD %p %s:%d", (head), __FILE__, __LINE__);
411
#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field)                  \
412
        if (*(head)->tqh_last != NULL)                                  \
413
                panic("TAILQ_INSERT_TAIL %p %s:%d", (head), __FILE__, __LINE__);
414
#define QUEUEDEBUG_TAILQ_OP(elm, field)                                 \
415
        if ((elm)->field.tqe_next &&                                    \
416
            (elm)->field.tqe_next->field.tqe_prev !=                    \
417
            &(elm)->field.tqe_next)                                     \
418
                panic("TAILQ_* forw %p %s:%d", (elm), __FILE__, __LINE__);\
419
        if (*(elm)->field.tqe_prev != (elm))                            \
420
                panic("TAILQ_* back %p %s:%d", (elm), __FILE__, __LINE__);
421
#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field)                    \
422
        if ((elm)->field.tqe_next == NULL &&                            \
423
            (head)->tqh_last != &(elm)->field.tqe_next)                 \
424
                panic("TAILQ_PREREMOVE head %p elm %p %s:%d",           \
425
                      (head), (elm), __FILE__, __LINE__);
426
#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field)                         \
427
        (elm)->field.tqe_next = (void *)1L;                             \
428
        (elm)->field.tqe_prev = (void *)1L;
429
#else
430
#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field)
431
#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field)
432
#define QUEUEDEBUG_TAILQ_OP(elm, field)
433
#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field)
434
#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field)
435
#endif
436
 
437
#define TAILQ_INIT(head) do {                                           \
438
        (head)->tqh_first = NULL;                                       \
439
        (head)->tqh_last = &(head)->tqh_first;                          \
440
} while (/*CONSTCOND*/0)
441
 
442
#define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
443
        QUEUEDEBUG_TAILQ_INSERT_HEAD((head), (elm), field)              \
444
        if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)        \
445
                (head)->tqh_first->field.tqe_prev =                     \
446
                    &(elm)->field.tqe_next;                             \
447
        else                                                            \
448
                (head)->tqh_last = &(elm)->field.tqe_next;              \
449
        (head)->tqh_first = (elm);                                      \
450
        (elm)->field.tqe_prev = &(head)->tqh_first;                     \
451
} while (/*CONSTCOND*/0)
452
 
453
#define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
454
        QUEUEDEBUG_TAILQ_INSERT_TAIL((head), (elm), field)              \
455
        (elm)->field.tqe_next = NULL;                                   \
456
        (elm)->field.tqe_prev = (head)->tqh_last;                       \
457
        *(head)->tqh_last = (elm);                                      \
458
        (head)->tqh_last = &(elm)->field.tqe_next;                      \
459
} while (/*CONSTCOND*/0)
460
 
461
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
462
        QUEUEDEBUG_TAILQ_OP((listelm), field)                           \
463
        if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
464
                (elm)->field.tqe_next->field.tqe_prev =                 \
465
                    &(elm)->field.tqe_next;                             \
466
        else                                                            \
467
                (head)->tqh_last = &(elm)->field.tqe_next;              \
468
        (listelm)->field.tqe_next = (elm);                              \
469
        (elm)->field.tqe_prev = &(listelm)->field.tqe_next;             \
470
} while (/*CONSTCOND*/0)
471
 
472
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
473
        QUEUEDEBUG_TAILQ_OP((listelm), field)                           \
474
        (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
475
        (elm)->field.tqe_next = (listelm);                              \
476
        *(listelm)->field.tqe_prev = (elm);                             \
477
        (listelm)->field.tqe_prev = &(elm)->field.tqe_next;             \
478
} while (/*CONSTCOND*/0)
479
 
480
#define TAILQ_REMOVE(head, elm, field) do {                             \
481
        QUEUEDEBUG_TAILQ_PREREMOVE((head), (elm), field)                \
482
        QUEUEDEBUG_TAILQ_OP((elm), field)                               \
483
        if (((elm)->field.tqe_next) != NULL)                            \
484
                (elm)->field.tqe_next->field.tqe_prev =                 \
485
                    (elm)->field.tqe_prev;                              \
486
        else                                                            \
487
                (head)->tqh_last = (elm)->field.tqe_prev;               \
488
        *(elm)->field.tqe_prev = (elm)->field.tqe_next;                 \
489
        QUEUEDEBUG_TAILQ_POSTREMOVE((elm), field);                      \
490
} while (/*CONSTCOND*/0)
491
 
492
#define TAILQ_FOREACH(var, head, field)                                 \
493
        for ((var) = ((head)->tqh_first);                               \
494
                (var);                                                  \
495
                (var) = ((var)->field.tqe_next))
496
 
497
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
498
        for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last));    \
499
                (var);                                                  \
500
                (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
501
 
502
/*
503
 * Tail queue access methods.
504
 */
505
#define TAILQ_EMPTY(head)               ((head)->tqh_first == NULL)
506
#define TAILQ_FIRST(head)               ((head)->tqh_first)
507
#define TAILQ_NEXT(elm, field)          ((elm)->field.tqe_next)
508
 
509
#define TAILQ_LAST(head, headname) \
510
        (*(((struct headname *)((head)->tqh_last))->tqh_last))
511
#define TAILQ_PREV(elm, headname, field) \
512
        (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
513
 
514
 
515
/*
516
 * Circular queue definitions.
517
 */
518
#define CIRCLEQ_HEAD(name, type)                                        \
519
struct name {                                                           \
520
        struct type *cqh_first;         /* first element */             \
521
        struct type *cqh_last;          /* last element */              \
522
}
523
 
524
#define CIRCLEQ_HEAD_INITIALIZER(head)                                  \
525
        { (void *)&head, (void *)&head }
526
 
527
#define CIRCLEQ_ENTRY(type)                                             \
528
struct {                                                                \
529
        struct type *cqe_next;          /* next element */              \
530
        struct type *cqe_prev;          /* previous element */          \
531
}
532
 
533
/*
534
 * Circular queue functions.
535
 */
536
#define CIRCLEQ_INIT(head) do {                                         \
537
        (head)->cqh_first = (void *)(head);                             \
538
        (head)->cqh_last = (void *)(head);                              \
539
} while (/*CONSTCOND*/0)
540
 
541
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do {            \
542
        (elm)->field.cqe_next = (listelm)->field.cqe_next;              \
543
        (elm)->field.cqe_prev = (listelm);                              \
544
        if ((listelm)->field.cqe_next == (void *)(head))                \
545
                (head)->cqh_last = (elm);                               \
546
        else                                                            \
547
                (listelm)->field.cqe_next->field.cqe_prev = (elm);      \
548
        (listelm)->field.cqe_next = (elm);                              \
549
} while (/*CONSTCOND*/0)
550
 
551
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do {           \
552
        (elm)->field.cqe_next = (listelm);                              \
553
        (elm)->field.cqe_prev = (listelm)->field.cqe_prev;              \
554
        if ((listelm)->field.cqe_prev == (void *)(head))                \
555
                (head)->cqh_first = (elm);                              \
556
        else                                                            \
557
                (listelm)->field.cqe_prev->field.cqe_next = (elm);      \
558
        (listelm)->field.cqe_prev = (elm);                              \
559
} while (/*CONSTCOND*/0)
560
 
561
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do {                      \
562
        (elm)->field.cqe_next = (head)->cqh_first;                      \
563
        (elm)->field.cqe_prev = (void *)(head);                         \
564
        if ((head)->cqh_last == (void *)(head))                         \
565
                (head)->cqh_last = (elm);                               \
566
        else                                                            \
567
                (head)->cqh_first->field.cqe_prev = (elm);              \
568
        (head)->cqh_first = (elm);                                      \
569
} while (/*CONSTCOND*/0)
570
 
571
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do {                      \
572
        (elm)->field.cqe_next = (void *)(head);                         \
573
        (elm)->field.cqe_prev = (head)->cqh_last;                       \
574
        if ((head)->cqh_first == (void *)(head))                        \
575
                (head)->cqh_first = (elm);                              \
576
        else                                                            \
577
                (head)->cqh_last->field.cqe_next = (elm);               \
578
        (head)->cqh_last = (elm);                                       \
579
} while (/*CONSTCOND*/0)
580
 
581
#define CIRCLEQ_REMOVE(head, elm, field) do {                           \
582
        if ((elm)->field.cqe_next == (void *)(head))                    \
583
                (head)->cqh_last = (elm)->field.cqe_prev;               \
584
        else                                                            \
585
                (elm)->field.cqe_next->field.cqe_prev =                 \
586
                    (elm)->field.cqe_prev;                              \
587
        if ((elm)->field.cqe_prev == (void *)(head))                    \
588
                (head)->cqh_first = (elm)->field.cqe_next;              \
589
        else                                                            \
590
                (elm)->field.cqe_prev->field.cqe_next =                 \
591
                    (elm)->field.cqe_next;                              \
592
} while (/*CONSTCOND*/0)
593
 
594
#define CIRCLEQ_FOREACH(var, head, field)                               \
595
        for ((var) = ((head)->cqh_first);                               \
596
                (var) != (void *)(head);                                \
597
                (var) = ((var)->field.cqe_next))
598
 
599
#define CIRCLEQ_FOREACH_REVERSE(var, head, field)                       \
600
        for ((var) = ((head)->cqh_last);                                \
601
                (var) != (void *)(head);                                \
602
                (var) = ((var)->field.cqe_prev))
603
 
604
/*
605
 * Circular queue access methods.
606
 */
607
#define CIRCLEQ_EMPTY(head)             ((head)->cqh_first == (void *)(head))
608
#define CIRCLEQ_FIRST(head)             ((head)->cqh_first)
609
#define CIRCLEQ_LAST(head)              ((head)->cqh_last)
610
#define CIRCLEQ_NEXT(elm, field)        ((elm)->field.cqe_next)
611
#define CIRCLEQ_PREV(elm, field)        ((elm)->field.cqe_prev)
612
#define CIRCLEQ_LOOP_NEXT(head, elm, field)                             \
613
        (((elm)->field.cqe_next == (void *)(head))                      \
614
            ? ((head)->cqh_first)                                       \
615
            : (elm->field.cqe_next))
616
#define CIRCLEQ_LOOP_PREV(head, elm, field)                             \
617
        (((elm)->field.cqe_prev == (void *)(head))                      \
618
            ? ((head)->cqh_last)                                        \
619
            : (elm->field.cqe_prev))
620
 
621
#endif  /* MLOMA__SYS_QUEUE_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.