1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _NSC_LIST_H 27 #define _NSC_LIST_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /* 34 * Generic lists support. 35 */ 36 37 38 /* 39 * Lists are circular and doubly-linked, with headers. 40 * When a list is empty, both pointers in the header 41 * point to the header itself. 42 */ 43 44 #if defined(_KERNEL) || defined(_KMEMUSER) 45 46 /* list element */ 47 typedef struct ls_elt { 48 struct ls_elt *ls_next; 49 struct ls_elt *ls_prev; 50 } ls_elt_t; 51 52 #endif /* _KERNEL || _KMEMUSER */ 53 54 #ifdef _KERNEL 55 56 /* 57 * All take as arguments side effect-free pointers to list structures 58 */ 59 #define LS_ISEMPTY(listp) \ 60 (((ls_elt_t *)(listp))->ls_next == (ls_elt_t *)(listp)) 61 #define LS_INIT(listp) { \ 62 ((ls_elt_t *)(listp))->ls_next = \ 63 ((ls_elt_t *)(listp))->ls_prev = \ 64 ((ls_elt_t *)(listp)); \ 65 } 66 67 #define LS_REMOVE(listp) ls_remove((ls_elt_t *)(listp)) 68 69 /* 70 * For these five, ptrs are to list elements, but qp and stackp are 71 * implicitly headers. 72 */ 73 #define LS_INS_BEFORE(oldp, newp) \ 74 ls_ins_before((ls_elt_t *)(oldp), (ls_elt_t *)(newp)) 75 76 #define LS_INS_AFTER(oldp, newp) \ 77 ls_ins_after((ls_elt_t *)(oldp), (ls_elt_t *)(newp)) 78 79 #define LS_INSQUE(qp, eltp) \ 80 ls_ins_before((ls_elt_t *)(qp), (ls_elt_t *)(eltp)) 81 82 /* result needs cast; 0 result if empty queue */ 83 #define LS_REMQUE(qp) ls_remque((ls_elt_t *)(qp)) 84 85 #define LS_PUSH(stackp, newp) \ 86 ls_ins_after((ls_elt_t *)(stackp), (ls_elt_t *)(newp)) 87 88 /* result needs cast; 0 result if empty stack */ 89 #define LS_POP(stackp) ls_remque((ls_elt_t *)(stackp)) 90 91 /* public function declarations */ 92 void ls_ins_before(ls_elt_t *, ls_elt_t *); 93 void ls_ins_after(ls_elt_t *, ls_elt_t *); 94 ls_elt_t *ls_remque(ls_elt_t *); 95 void ls_remove(ls_elt_t *); 96 97 #endif /* _KERNEL */ 98 99 #if defined(_KERNEL) || defined(_KMEMUSER) 100 101 typedef struct llist { 102 struct llist *volatile flink; /* forward link */ 103 struct llist *volatile rlink; /* reverse link */ 104 } llist_t; 105 106 #endif /* _KERNEL || _KMEMUSER */ 107 108 #ifdef _KERNEL 109 110 #define INITQUE(l) ((l)->flink = (l)->rlink = (l)) 111 #define EMPTYQUE(l) ((l)->flink == (l)) 112 113 #endif /* _KERNEL */ 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 #endif /* _NSC_LIST_H */