1 /* 2 * Copyright (c) 2002, Stockholms Universitet 3 * (Stockholm University, Stockholm Sweden) 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 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 * 17 * 3. Neither the name of the university nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* $arla: xfs_queue.h,v 1.1 2002/11/28 06:24:23 lha Exp $ */ 35 36 /* Inspirered by the queue macros in BSD. */ 37 38 #ifndef NNPFS_QUEUE_H 39 #define NNPFS_QUEUE_H 1 40 41 /* Define a head. */ 42 #define NNPQUEUE_HEAD(name, type) \ 43 struct name { \ 44 struct type *nnpq_first; \ 45 struct type **nnpq_last; \ 46 } 47 48 /* Defining a entry. */ 49 #define NNPQUEUE_ENTRY(type) \ 50 struct { \ 51 struct type *nnpq_next, **nnpq_prev; \ 52 } 53 54 /* Is the queue empty. */ 55 #define NNPQUEUE_EMPTY(head) \ 56 ((head)->nnpq_first == NULL) 57 58 /* Init head. */ 59 #define NNPQUEUE_INIT(head) do { \ 60 (head)->nnpq_first = NULL; \ 61 (head)->nnpq_last = &(head)->nnpq_first; \ 62 } while (0) 63 64 /* Insert elm after listelm, field is named. */ 65 #define NNPQUEUE_INSERT_HEAD(head, elm, field) do { \ 66 if (((elm)->field.nnpq_next = (head)->nnpq_first) != NULL) \ 67 (head)->nnpq_first->field.nnpq_prev = \ 68 &(elm)->field.nnpq_next; \ 69 else \ 70 (head)->nnpq_last = &(elm)->field.nnpq_next; \ 71 (head)->nnpq_first = (elm); \ 72 (elm)->field.nnpq_prev = &(head)->nnpq_first; \ 73 } while (0) 74 75 /* Remove an entry. */ 76 #define NNPQUEUE_REMOVE(elm,head,field) do { \ 77 if (((elm)->field.nnpq_next) != NULL) \ 78 (elm)->field.nnpq_next->field.nnpq_prev = \ 79 (elm)->field.nnpq_prev; \ 80 else \ 81 (head)->nnpq_last = (elm)->field.nnpq_prev; \ 82 *(elm)->field.nnpq_prev = (elm)->field.nnpq_next; \ 83 } while(0) 84 85 /* Iterate over the list. */ 86 #define NNPQUEUE_FOREACH(var,head,field) \ 87 for ((var) = ((head)->nnpq_first); \ 88 (var); \ 89 (var) = ((var)->field.nnpq_next)) 90 91 #endif /* NNPFS_QUEUE_H */