iqueue.h - dedup - deduplicating backup program Err bitreich.org 70 hgit clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ URL:git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ bitreich.org 70 1Log /scm/dedup/log.gph bitreich.org 70 1Files /scm/dedup/files.gph bitreich.org 70 1Refs /scm/dedup/refs.gph bitreich.org 70 1Tags /scm/dedup/tag bitreich.org 70 1README /scm/dedup/file/README.gph bitreich.org 70 1LICENSE /scm/dedup/file/LICENSE.gph bitreich.org 70 i--- Err bitreich.org 70 iqueue.h (18350B) Err bitreich.org 70 i--- Err bitreich.org 70 i 1 /* $OpenBSD: queue.h,v 1.45 2018/07/12 14:22:54 sashan Exp $ */ Err bitreich.org 70 i 2 /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ Err bitreich.org 70 i 3 Err bitreich.org 70 i 4 /* Err bitreich.org 70 i 5 * Copyright (c) 1991, 1993 Err bitreich.org 70 i 6 * The Regents of the University of California. All rights reserved. Err bitreich.org 70 i 7 * Err bitreich.org 70 i 8 * Redistribution and use in source and binary forms, with or without Err bitreich.org 70 i 9 * modification, are permitted provided that the following conditions Err bitreich.org 70 i 10 * are met: Err bitreich.org 70 i 11 * 1. Redistributions of source code must retain the above copyright Err bitreich.org 70 i 12 * notice, this list of conditions and the following disclaimer. Err bitreich.org 70 i 13 * 2. Redistributions in binary form must reproduce the above copyright Err bitreich.org 70 i 14 * notice, this list of conditions and the following disclaimer in the Err bitreich.org 70 i 15 * documentation and/or other materials provided with the distribution. Err bitreich.org 70 i 16 * 3. Neither the name of the University nor the names of its contributors Err bitreich.org 70 i 17 * may be used to endorse or promote products derived from this software Err bitreich.org 70 i 18 * without specific prior written permission. Err bitreich.org 70 i 19 * Err bitreich.org 70 i 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND Err bitreich.org 70 i 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE Err bitreich.org 70 i 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE Err bitreich.org 70 i 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE Err bitreich.org 70 i 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL Err bitreich.org 70 i 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS Err bitreich.org 70 i 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) Err bitreich.org 70 i 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT Err bitreich.org 70 i 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY Err bitreich.org 70 i 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF Err bitreich.org 70 i 30 * SUCH DAMAGE. Err bitreich.org 70 i 31 * Err bitreich.org 70 i 32 * @(#)queue.h 8.5 (Berkeley) 8/20/94 Err bitreich.org 70 i 33 */ Err bitreich.org 70 i 34 Err bitreich.org 70 i 35 #ifndef _SYS_QUEUE_H_ Err bitreich.org 70 i 36 #define _SYS_QUEUE_H_ Err bitreich.org 70 i 37 Err bitreich.org 70 i 38 /* Err bitreich.org 70 i 39 * This file defines five types of data structures: singly-linked lists, Err bitreich.org 70 i 40 * lists, simple queues, tail queues and XOR simple queues. Err bitreich.org 70 i 41 * Err bitreich.org 70 i 42 * Err bitreich.org 70 i 43 * A singly-linked list is headed by a single forward pointer. The elements Err bitreich.org 70 i 44 * are singly linked for minimum space and pointer manipulation overhead at Err bitreich.org 70 i 45 * the expense of O(n) removal for arbitrary elements. New elements can be Err bitreich.org 70 i 46 * added to the list after an existing element or at the head of the list. Err bitreich.org 70 i 47 * Elements being removed from the head of the list should use the explicit Err bitreich.org 70 i 48 * macro for this purpose for optimum efficiency. A singly-linked list may Err bitreich.org 70 i 49 * only be traversed in the forward direction. Singly-linked lists are ideal Err bitreich.org 70 i 50 * for applications with large datasets and few or no removals or for Err bitreich.org 70 i 51 * implementing a LIFO queue. Err bitreich.org 70 i 52 * Err bitreich.org 70 i 53 * A list is headed by a single forward pointer (or an array of forward Err bitreich.org 70 i 54 * pointers for a hash table header). The elements are doubly linked Err bitreich.org 70 i 55 * so that an arbitrary element can be removed without a need to Err bitreich.org 70 i 56 * traverse the list. New elements can be added to the list before Err bitreich.org 70 i 57 * or after an existing element or at the head of the list. A list Err bitreich.org 70 i 58 * may only be traversed in the forward direction. Err bitreich.org 70 i 59 * Err bitreich.org 70 i 60 * A simple queue is headed by a pair of pointers, one to the head of the Err bitreich.org 70 i 61 * list and the other to the tail of the list. The elements are singly Err bitreich.org 70 i 62 * linked to save space, so elements can only be removed from the Err bitreich.org 70 i 63 * head of the list. New elements can be added to the list before or after Err bitreich.org 70 i 64 * an existing element, at the head of the list, or at the end of the Err bitreich.org 70 i 65 * list. A simple queue may only be traversed in the forward direction. Err bitreich.org 70 i 66 * Err bitreich.org 70 i 67 * A tail queue is headed by a pair of pointers, one to the head of the Err bitreich.org 70 i 68 * list and the other to the tail of the list. The elements are doubly Err bitreich.org 70 i 69 * linked so that an arbitrary element can be removed without a need to Err bitreich.org 70 i 70 * traverse the list. New elements can be added to the list before or Err bitreich.org 70 i 71 * after an existing element, at the head of the list, or at the end of Err bitreich.org 70 i 72 * the list. A tail queue may be traversed in either direction. Err bitreich.org 70 i 73 * Err bitreich.org 70 i 74 * An XOR simple queue is used in the same way as a regular simple queue. Err bitreich.org 70 i 75 * The difference is that the head structure also includes a "cookie" that Err bitreich.org 70 i 76 * is XOR'd with the queue pointer (first, last or next) to generate the Err bitreich.org 70 i 77 * real pointer value. Err bitreich.org 70 i 78 * Err bitreich.org 70 i 79 * For details on the use of these macros, see the queue(3) manual page. Err bitreich.org 70 i 80 */ Err bitreich.org 70 i 81 Err bitreich.org 70 i 82 #if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC)) Err bitreich.org 70 i 83 #define _Q_INVALID ((void *)-1) Err bitreich.org 70 i 84 #define _Q_INVALIDATE(a) (a) = _Q_INVALID Err bitreich.org 70 i 85 #else Err bitreich.org 70 i 86 #define _Q_INVALIDATE(a) Err bitreich.org 70 i 87 #endif Err bitreich.org 70 i 88 Err bitreich.org 70 i 89 /* Err bitreich.org 70 i 90 * Singly-linked List definitions. Err bitreich.org 70 i 91 */ Err bitreich.org 70 i 92 #define SLIST_HEAD(name, type) \ Err bitreich.org 70 i 93 struct name { \ Err bitreich.org 70 i 94 struct type *slh_first; /* first element */ \ Err bitreich.org 70 i 95 } Err bitreich.org 70 i 96 Err bitreich.org 70 i 97 #define SLIST_HEAD_INITIALIZER(head) \ Err bitreich.org 70 i 98 { NULL } Err bitreich.org 70 i 99 Err bitreich.org 70 i 100 #define SLIST_ENTRY(type) \ Err bitreich.org 70 i 101 struct { \ Err bitreich.org 70 i 102 struct type *sle_next; /* next element */ \ Err bitreich.org 70 i 103 } Err bitreich.org 70 i 104 Err bitreich.org 70 i 105 /* Err bitreich.org 70 i 106 * Singly-linked List access methods. Err bitreich.org 70 i 107 */ Err bitreich.org 70 i 108 #define SLIST_FIRST(head) ((head)->slh_first) Err bitreich.org 70 i 109 #define SLIST_END(head) NULL Err bitreich.org 70 i 110 #define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) Err bitreich.org 70 i 111 #define SLIST_NEXT(elm, field) ((elm)->field.sle_next) Err bitreich.org 70 i 112 Err bitreich.org 70 i 113 #define SLIST_FOREACH(var, head, field) \ Err bitreich.org 70 i 114 for((var) = SLIST_FIRST(head); \ Err bitreich.org 70 i 115 (var) != SLIST_END(head); \ Err bitreich.org 70 i 116 (var) = SLIST_NEXT(var, field)) Err bitreich.org 70 i 117 Err bitreich.org 70 i 118 #define SLIST_FOREACH_SAFE(var, head, field, tvar) \ Err bitreich.org 70 i 119 for ((var) = SLIST_FIRST(head); \ Err bitreich.org 70 i 120 (var) && ((tvar) = SLIST_NEXT(var, field), 1); \ Err bitreich.org 70 i 121 (var) = (tvar)) Err bitreich.org 70 i 122 Err bitreich.org 70 i 123 /* Err bitreich.org 70 i 124 * Singly-linked List functions. Err bitreich.org 70 i 125 */ Err bitreich.org 70 i 126 #define SLIST_INIT(head) { \ Err bitreich.org 70 i 127 SLIST_FIRST(head) = SLIST_END(head); \ Err bitreich.org 70 i 128 } Err bitreich.org 70 i 129 Err bitreich.org 70 i 130 #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ Err bitreich.org 70 i 131 (elm)->field.sle_next = (slistelm)->field.sle_next; \ Err bitreich.org 70 i 132 (slistelm)->field.sle_next = (elm); \ Err bitreich.org 70 i 133 } while (0) Err bitreich.org 70 i 134 Err bitreich.org 70 i 135 #define SLIST_INSERT_HEAD(head, elm, field) do { \ Err bitreich.org 70 i 136 (elm)->field.sle_next = (head)->slh_first; \ Err bitreich.org 70 i 137 (head)->slh_first = (elm); \ Err bitreich.org 70 i 138 } while (0) Err bitreich.org 70 i 139 Err bitreich.org 70 i 140 #define SLIST_REMOVE_AFTER(elm, field) do { \ Err bitreich.org 70 i 141 (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ Err bitreich.org 70 i 142 } while (0) Err bitreich.org 70 i 143 Err bitreich.org 70 i 144 #define SLIST_REMOVE_HEAD(head, field) do { \ Err bitreich.org 70 i 145 (head)->slh_first = (head)->slh_first->field.sle_next; \ Err bitreich.org 70 i 146 } while (0) Err bitreich.org 70 i 147 Err bitreich.org 70 i 148 #define SLIST_REMOVE(head, elm, type, field) do { \ Err bitreich.org 70 i 149 if ((head)->slh_first == (elm)) { \ Err bitreich.org 70 i 150 SLIST_REMOVE_HEAD((head), field); \ Err bitreich.org 70 i 151 } else { \ Err bitreich.org 70 i 152 struct type *curelm = (head)->slh_first; \ Err bitreich.org 70 i 153 \ Err bitreich.org 70 i 154 while (curelm->field.sle_next != (elm)) \ Err bitreich.org 70 i 155 curelm = curelm->field.sle_next; \ Err bitreich.org 70 i 156 curelm->field.sle_next = \ Err bitreich.org 70 i 157 curelm->field.sle_next->field.sle_next; \ Err bitreich.org 70 i 158 } \ Err bitreich.org 70 i 159 _Q_INVALIDATE((elm)->field.sle_next); \ Err bitreich.org 70 i 160 } while (0) Err bitreich.org 70 i 161 Err bitreich.org 70 i 162 /* Err bitreich.org 70 i 163 * List definitions. Err bitreich.org 70 i 164 */ Err bitreich.org 70 i 165 #define LIST_HEAD(name, type) \ Err bitreich.org 70 i 166 struct name { \ Err bitreich.org 70 i 167 struct type *lh_first; /* first element */ \ Err bitreich.org 70 i 168 } Err bitreich.org 70 i 169 Err bitreich.org 70 i 170 #define LIST_HEAD_INITIALIZER(head) \ Err bitreich.org 70 i 171 { NULL } Err bitreich.org 70 i 172 Err bitreich.org 70 i 173 #define LIST_ENTRY(type) \ Err bitreich.org 70 i 174 struct { \ Err bitreich.org 70 i 175 struct type *le_next; /* next element */ \ Err bitreich.org 70 i 176 struct type **le_prev; /* address of previous next element */ \ Err bitreich.org 70 i 177 } Err bitreich.org 70 i 178 Err bitreich.org 70 i 179 /* Err bitreich.org 70 i 180 * List access methods. Err bitreich.org 70 i 181 */ Err bitreich.org 70 i 182 #define LIST_FIRST(head) ((head)->lh_first) Err bitreich.org 70 i 183 #define LIST_END(head) NULL Err bitreich.org 70 i 184 #define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) Err bitreich.org 70 i 185 #define LIST_NEXT(elm, field) ((elm)->field.le_next) Err bitreich.org 70 i 186 Err bitreich.org 70 i 187 #define LIST_FOREACH(var, head, field) \ Err bitreich.org 70 i 188 for((var) = LIST_FIRST(head); \ Err bitreich.org 70 i 189 (var)!= LIST_END(head); \ Err bitreich.org 70 i 190 (var) = LIST_NEXT(var, field)) Err bitreich.org 70 i 191 Err bitreich.org 70 i 192 #define LIST_FOREACH_SAFE(var, head, field, tvar) \ Err bitreich.org 70 i 193 for ((var) = LIST_FIRST(head); \ Err bitreich.org 70 i 194 (var) && ((tvar) = LIST_NEXT(var, field), 1); \ Err bitreich.org 70 i 195 (var) = (tvar)) Err bitreich.org 70 i 196 Err bitreich.org 70 i 197 /* Err bitreich.org 70 i 198 * List functions. Err bitreich.org 70 i 199 */ Err bitreich.org 70 i 200 #define LIST_INIT(head) do { \ Err bitreich.org 70 i 201 LIST_FIRST(head) = LIST_END(head); \ Err bitreich.org 70 i 202 } while (0) Err bitreich.org 70 i 203 Err bitreich.org 70 i 204 #define LIST_INSERT_AFTER(listelm, elm, field) do { \ Err bitreich.org 70 i 205 if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ Err bitreich.org 70 i 206 (listelm)->field.le_next->field.le_prev = \ Err bitreich.org 70 i 207 &(elm)->field.le_next; \ Err bitreich.org 70 i 208 (listelm)->field.le_next = (elm); \ Err bitreich.org 70 i 209 (elm)->field.le_prev = &(listelm)->field.le_next; \ Err bitreich.org 70 i 210 } while (0) Err bitreich.org 70 i 211 Err bitreich.org 70 i 212 #define LIST_INSERT_BEFORE(listelm, elm, field) do { \ Err bitreich.org 70 i 213 (elm)->field.le_prev = (listelm)->field.le_prev; \ Err bitreich.org 70 i 214 (elm)->field.le_next = (listelm); \ Err bitreich.org 70 i 215 *(listelm)->field.le_prev = (elm); \ Err bitreich.org 70 i 216 (listelm)->field.le_prev = &(elm)->field.le_next; \ Err bitreich.org 70 i 217 } while (0) Err bitreich.org 70 i 218 Err bitreich.org 70 i 219 #define LIST_INSERT_HEAD(head, elm, field) do { \ Err bitreich.org 70 i 220 if (((elm)->field.le_next = (head)->lh_first) != NULL) \ Err bitreich.org 70 i 221 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ Err bitreich.org 70 i 222 (head)->lh_first = (elm); \ Err bitreich.org 70 i 223 (elm)->field.le_prev = &(head)->lh_first; \ Err bitreich.org 70 i 224 } while (0) Err bitreich.org 70 i 225 Err bitreich.org 70 i 226 #define LIST_REMOVE(elm, field) do { \ Err bitreich.org 70 i 227 if ((elm)->field.le_next != NULL) \ Err bitreich.org 70 i 228 (elm)->field.le_next->field.le_prev = \ Err bitreich.org 70 i 229 (elm)->field.le_prev; \ Err bitreich.org 70 i 230 *(elm)->field.le_prev = (elm)->field.le_next; \ Err bitreich.org 70 i 231 _Q_INVALIDATE((elm)->field.le_prev); \ Err bitreich.org 70 i 232 _Q_INVALIDATE((elm)->field.le_next); \ Err bitreich.org 70 i 233 } while (0) Err bitreich.org 70 i 234 Err bitreich.org 70 i 235 #define LIST_REPLACE(elm, elm2, field) do { \ Err bitreich.org 70 i 236 if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ Err bitreich.org 70 i 237 (elm2)->field.le_next->field.le_prev = \ Err bitreich.org 70 i 238 &(elm2)->field.le_next; \ Err bitreich.org 70 i 239 (elm2)->field.le_prev = (elm)->field.le_prev; \ Err bitreich.org 70 i 240 *(elm2)->field.le_prev = (elm2); \ Err bitreich.org 70 i 241 _Q_INVALIDATE((elm)->field.le_prev); \ Err bitreich.org 70 i 242 _Q_INVALIDATE((elm)->field.le_next); \ Err bitreich.org 70 i 243 } while (0) Err bitreich.org 70 i 244 Err bitreich.org 70 i 245 /* Err bitreich.org 70 i 246 * Simple queue definitions. Err bitreich.org 70 i 247 */ Err bitreich.org 70 i 248 #define SIMPLEQ_HEAD(name, type) \ Err bitreich.org 70 i 249 struct name { \ Err bitreich.org 70 i 250 struct type *sqh_first; /* first element */ \ Err bitreich.org 70 i 251 struct type **sqh_last; /* addr of last next element */ \ Err bitreich.org 70 i 252 } Err bitreich.org 70 i 253 Err bitreich.org 70 i 254 #define SIMPLEQ_HEAD_INITIALIZER(head) \ Err bitreich.org 70 i 255 { NULL, &(head).sqh_first } Err bitreich.org 70 i 256 Err bitreich.org 70 i 257 #define SIMPLEQ_ENTRY(type) \ Err bitreich.org 70 i 258 struct { \ Err bitreich.org 70 i 259 struct type *sqe_next; /* next element */ \ Err bitreich.org 70 i 260 } Err bitreich.org 70 i 261 Err bitreich.org 70 i 262 /* Err bitreich.org 70 i 263 * Simple queue access methods. Err bitreich.org 70 i 264 */ Err bitreich.org 70 i 265 #define SIMPLEQ_FIRST(head) ((head)->sqh_first) Err bitreich.org 70 i 266 #define SIMPLEQ_END(head) NULL Err bitreich.org 70 i 267 #define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) Err bitreich.org 70 i 268 #define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) Err bitreich.org 70 i 269 Err bitreich.org 70 i 270 #define SIMPLEQ_FOREACH(var, head, field) \ Err bitreich.org 70 i 271 for((var) = SIMPLEQ_FIRST(head); \ Err bitreich.org 70 i 272 (var) != SIMPLEQ_END(head); \ Err bitreich.org 70 i 273 (var) = SIMPLEQ_NEXT(var, field)) Err bitreich.org 70 i 274 Err bitreich.org 70 i 275 #define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ Err bitreich.org 70 i 276 for ((var) = SIMPLEQ_FIRST(head); \ Err bitreich.org 70 i 277 (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1); \ Err bitreich.org 70 i 278 (var) = (tvar)) Err bitreich.org 70 i 279 Err bitreich.org 70 i 280 /* Err bitreich.org 70 i 281 * Simple queue functions. Err bitreich.org 70 i 282 */ Err bitreich.org 70 i 283 #define SIMPLEQ_INIT(head) do { \ Err bitreich.org 70 i 284 (head)->sqh_first = NULL; \ Err bitreich.org 70 i 285 (head)->sqh_last = &(head)->sqh_first; \ Err bitreich.org 70 i 286 } while (0) Err bitreich.org 70 i 287 Err bitreich.org 70 i 288 #define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ Err bitreich.org 70 i 289 if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ Err bitreich.org 70 i 290 (head)->sqh_last = &(elm)->field.sqe_next; \ Err bitreich.org 70 i 291 (head)->sqh_first = (elm); \ Err bitreich.org 70 i 292 } while (0) Err bitreich.org 70 i 293 Err bitreich.org 70 i 294 #define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ Err bitreich.org 70 i 295 (elm)->field.sqe_next = NULL; \ Err bitreich.org 70 i 296 *(head)->sqh_last = (elm); \ Err bitreich.org 70 i 297 (head)->sqh_last = &(elm)->field.sqe_next; \ Err bitreich.org 70 i 298 } while (0) Err bitreich.org 70 i 299 Err bitreich.org 70 i 300 #define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ Err bitreich.org 70 i 301 if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ Err bitreich.org 70 i 302 (head)->sqh_last = &(elm)->field.sqe_next; \ Err bitreich.org 70 i 303 (listelm)->field.sqe_next = (elm); \ Err bitreich.org 70 i 304 } while (0) Err bitreich.org 70 i 305 Err bitreich.org 70 i 306 #define SIMPLEQ_REMOVE_HEAD(head, field) do { \ Err bitreich.org 70 i 307 if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ Err bitreich.org 70 i 308 (head)->sqh_last = &(head)->sqh_first; \ Err bitreich.org 70 i 309 } while (0) Err bitreich.org 70 i 310 Err bitreich.org 70 i 311 #define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ Err bitreich.org 70 i 312 if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \ Err bitreich.org 70 i 313 == NULL) \ Err bitreich.org 70 i 314 (head)->sqh_last = &(elm)->field.sqe_next; \ Err bitreich.org 70 i 315 } while (0) Err bitreich.org 70 i 316 Err bitreich.org 70 i 317 #define SIMPLEQ_CONCAT(head1, head2) do { \ Err bitreich.org 70 i 318 if (!SIMPLEQ_EMPTY((head2))) { \ Err bitreich.org 70 i 319 *(head1)->sqh_last = (head2)->sqh_first; \ Err bitreich.org 70 i 320 (head1)->sqh_last = (head2)->sqh_last; \ Err bitreich.org 70 i 321 SIMPLEQ_INIT((head2)); \ Err bitreich.org 70 i 322 } \ Err bitreich.org 70 i 323 } while (0) Err bitreich.org 70 i 324 Err bitreich.org 70 i 325 /* Err bitreich.org 70 i 326 * XOR Simple queue definitions. Err bitreich.org 70 i 327 */ Err bitreich.org 70 i 328 #define XSIMPLEQ_HEAD(name, type) \ Err bitreich.org 70 i 329 struct name { \ Err bitreich.org 70 i 330 struct type *sqx_first; /* first element */ \ Err bitreich.org 70 i 331 struct type **sqx_last; /* addr of last next element */ \ Err bitreich.org 70 i 332 unsigned long sqx_cookie; \ Err bitreich.org 70 i 333 } Err bitreich.org 70 i 334 Err bitreich.org 70 i 335 #define XSIMPLEQ_ENTRY(type) \ Err bitreich.org 70 i 336 struct { \ Err bitreich.org 70 i 337 struct type *sqx_next; /* next element */ \ Err bitreich.org 70 i 338 } Err bitreich.org 70 i 339 Err bitreich.org 70 i 340 /* Err bitreich.org 70 i 341 * XOR Simple queue access methods. Err bitreich.org 70 i 342 */ Err bitreich.org 70 i 343 #define XSIMPLEQ_XOR(head, ptr) ((__typeof(ptr))((head)->sqx_cookie ^ \ Err bitreich.org 70 i 344 (unsigned long)(ptr))) Err bitreich.org 70 i 345 #define XSIMPLEQ_FIRST(head) XSIMPLEQ_XOR(head, ((head)->sqx_first)) Err bitreich.org 70 i 346 #define XSIMPLEQ_END(head) NULL Err bitreich.org 70 i 347 #define XSIMPLEQ_EMPTY(head) (XSIMPLEQ_FIRST(head) == XSIMPLEQ_END(head)) Err bitreich.org 70 i 348 #define XSIMPLEQ_NEXT(head, elm, field) XSIMPLEQ_XOR(head, ((elm)->field.sqx_next)) Err bitreich.org 70 i 349 Err bitreich.org 70 i 350 Err bitreich.org 70 i 351 #define XSIMPLEQ_FOREACH(var, head, field) \ Err bitreich.org 70 i 352 for ((var) = XSIMPLEQ_FIRST(head); \ Err bitreich.org 70 i 353 (var) != XSIMPLEQ_END(head); \ Err bitreich.org 70 i 354 (var) = XSIMPLEQ_NEXT(head, var, field)) Err bitreich.org 70 i 355 Err bitreich.org 70 i 356 #define XSIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ Err bitreich.org 70 i 357 for ((var) = XSIMPLEQ_FIRST(head); \ Err bitreich.org 70 i 358 (var) && ((tvar) = XSIMPLEQ_NEXT(head, var, field), 1); \ Err bitreich.org 70 i 359 (var) = (tvar)) Err bitreich.org 70 i 360 Err bitreich.org 70 i 361 /* Err bitreich.org 70 i 362 * XOR Simple queue functions. Err bitreich.org 70 i 363 */ Err bitreich.org 70 i 364 #define XSIMPLEQ_INIT(head) do { \ Err bitreich.org 70 i 365 arc4random_buf(&(head)->sqx_cookie, sizeof((head)->sqx_cookie)); \ Err bitreich.org 70 i 366 (head)->sqx_first = XSIMPLEQ_XOR(head, NULL); \ Err bitreich.org 70 i 367 (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \ Err bitreich.org 70 i 368 } while (0) Err bitreich.org 70 i 369 Err bitreich.org 70 i 370 #define XSIMPLEQ_INSERT_HEAD(head, elm, field) do { \ Err bitreich.org 70 i 371 if (((elm)->field.sqx_next = (head)->sqx_first) == \ Err bitreich.org 70 i 372 XSIMPLEQ_XOR(head, NULL)) \ Err bitreich.org 70 i 373 (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ Err bitreich.org 70 i 374 (head)->sqx_first = XSIMPLEQ_XOR(head, (elm)); \ Err bitreich.org 70 i 375 } while (0) Err bitreich.org 70 i 376 Err bitreich.org 70 i 377 #define XSIMPLEQ_INSERT_TAIL(head, elm, field) do { \ Err bitreich.org 70 i 378 (elm)->field.sqx_next = XSIMPLEQ_XOR(head, NULL); \ Err bitreich.org 70 i 379 *(XSIMPLEQ_XOR(head, (head)->sqx_last)) = XSIMPLEQ_XOR(head, (elm)); \ Err bitreich.org 70 i 380 (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ Err bitreich.org 70 i 381 } while (0) Err bitreich.org 70 i 382 Err bitreich.org 70 i 383 #define XSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ Err bitreich.org 70 i 384 if (((elm)->field.sqx_next = (listelm)->field.sqx_next) == \ Err bitreich.org 70 i 385 XSIMPLEQ_XOR(head, NULL)) \ Err bitreich.org 70 i 386 (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ Err bitreich.org 70 i 387 (listelm)->field.sqx_next = XSIMPLEQ_XOR(head, (elm)); \ Err bitreich.org 70 i 388 } while (0) Err bitreich.org 70 i 389 Err bitreich.org 70 i 390 #define XSIMPLEQ_REMOVE_HEAD(head, field) do { \ Err bitreich.org 70 i 391 if (((head)->sqx_first = XSIMPLEQ_XOR(head, \ Err bitreich.org 70 i 392 (head)->sqx_first)->field.sqx_next) == XSIMPLEQ_XOR(head, NULL)) \ Err bitreich.org 70 i 393 (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \ Err bitreich.org 70 i 394 } while (0) Err bitreich.org 70 i 395 Err bitreich.org 70 i 396 #define XSIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ Err bitreich.org 70 i 397 if (((elm)->field.sqx_next = XSIMPLEQ_XOR(head, \ Err bitreich.org 70 i 398 (elm)->field.sqx_next)->field.sqx_next) \ Err bitreich.org 70 i 399 == XSIMPLEQ_XOR(head, NULL)) \ Err bitreich.org 70 i 400 (head)->sqx_last = \ Err bitreich.org 70 i 401 XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ Err bitreich.org 70 i 402 } while (0) Err bitreich.org 70 i 403 Err bitreich.org 70 i 404 Err bitreich.org 70 i 405 /* Err bitreich.org 70 i 406 * Tail queue definitions. Err bitreich.org 70 i 407 */ Err bitreich.org 70 i 408 #define TAILQ_HEAD(name, type) \ Err bitreich.org 70 i 409 struct name { \ Err bitreich.org 70 i 410 struct type *tqh_first; /* first element */ \ Err bitreich.org 70 i 411 struct type **tqh_last; /* addr of last next element */ \ Err bitreich.org 70 i 412 } Err bitreich.org 70 i 413 Err bitreich.org 70 i 414 #define TAILQ_HEAD_INITIALIZER(head) \ Err bitreich.org 70 i 415 { NULL, &(head).tqh_first } Err bitreich.org 70 i 416 Err bitreich.org 70 i 417 #define TAILQ_ENTRY(type) \ Err bitreich.org 70 i 418 struct { \ Err bitreich.org 70 i 419 struct type *tqe_next; /* next element */ \ Err bitreich.org 70 i 420 struct type **tqe_prev; /* address of previous next element */ \ Err bitreich.org 70 i 421 } Err bitreich.org 70 i 422 Err bitreich.org 70 i 423 /* Err bitreich.org 70 i 424 * Tail queue access methods. Err bitreich.org 70 i 425 */ Err bitreich.org 70 i 426 #define TAILQ_FIRST(head) ((head)->tqh_first) Err bitreich.org 70 i 427 #define TAILQ_END(head) NULL Err bitreich.org 70 i 428 #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) Err bitreich.org 70 i 429 #define TAILQ_LAST(head, headname) \ Err bitreich.org 70 i 430 (*(((struct headname *)((head)->tqh_last))->tqh_last)) Err bitreich.org 70 i 431 /* XXX */ Err bitreich.org 70 i 432 #define TAILQ_PREV(elm, headname, field) \ Err bitreich.org 70 i 433 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) Err bitreich.org 70 i 434 #define TAILQ_EMPTY(head) \ Err bitreich.org 70 i 435 (TAILQ_FIRST(head) == TAILQ_END(head)) Err bitreich.org 70 i 436 Err bitreich.org 70 i 437 #define TAILQ_FOREACH(var, head, field) \ Err bitreich.org 70 i 438 for((var) = TAILQ_FIRST(head); \ Err bitreich.org 70 i 439 (var) != TAILQ_END(head); \ Err bitreich.org 70 i 440 (var) = TAILQ_NEXT(var, field)) Err bitreich.org 70 i 441 Err bitreich.org 70 i 442 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ Err bitreich.org 70 i 443 for ((var) = TAILQ_FIRST(head); \ Err bitreich.org 70 i 444 (var) != TAILQ_END(head) && \ Err bitreich.org 70 i 445 ((tvar) = TAILQ_NEXT(var, field), 1); \ Err bitreich.org 70 i 446 (var) = (tvar)) Err bitreich.org 70 i 447 Err bitreich.org 70 i 448 Err bitreich.org 70 i 449 #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ Err bitreich.org 70 i 450 for((var) = TAILQ_LAST(head, headname); \ Err bitreich.org 70 i 451 (var) != TAILQ_END(head); \ Err bitreich.org 70 i 452 (var) = TAILQ_PREV(var, headname, field)) Err bitreich.org 70 i 453 Err bitreich.org 70 i 454 #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ Err bitreich.org 70 i 455 for ((var) = TAILQ_LAST(head, headname); \ Err bitreich.org 70 i 456 (var) != TAILQ_END(head) && \ Err bitreich.org 70 i 457 ((tvar) = TAILQ_PREV(var, headname, field), 1); \ Err bitreich.org 70 i 458 (var) = (tvar)) Err bitreich.org 70 i 459 Err bitreich.org 70 i 460 /* Err bitreich.org 70 i 461 * Tail queue functions. Err bitreich.org 70 i 462 */ Err bitreich.org 70 i 463 #define TAILQ_INIT(head) do { \ Err bitreich.org 70 i 464 (head)->tqh_first = NULL; \ Err bitreich.org 70 i 465 (head)->tqh_last = &(head)->tqh_first; \ Err bitreich.org 70 i 466 } while (0) Err bitreich.org 70 i 467 Err bitreich.org 70 i 468 #define TAILQ_INSERT_HEAD(head, elm, field) do { \ Err bitreich.org 70 i 469 if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ Err bitreich.org 70 i 470 (head)->tqh_first->field.tqe_prev = \ Err bitreich.org 70 i 471 &(elm)->field.tqe_next; \ Err bitreich.org 70 i 472 else \ Err bitreich.org 70 i 473 (head)->tqh_last = &(elm)->field.tqe_next; \ Err bitreich.org 70 i 474 (head)->tqh_first = (elm); \ Err bitreich.org 70 i 475 (elm)->field.tqe_prev = &(head)->tqh_first; \ Err bitreich.org 70 i 476 } while (0) Err bitreich.org 70 i 477 Err bitreich.org 70 i 478 #define TAILQ_INSERT_TAIL(head, elm, field) do { \ Err bitreich.org 70 i 479 (elm)->field.tqe_next = NULL; \ Err bitreich.org 70 i 480 (elm)->field.tqe_prev = (head)->tqh_last; \ Err bitreich.org 70 i 481 *(head)->tqh_last = (elm); \ Err bitreich.org 70 i 482 (head)->tqh_last = &(elm)->field.tqe_next; \ Err bitreich.org 70 i 483 } while (0) Err bitreich.org 70 i 484 Err bitreich.org 70 i 485 #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ Err bitreich.org 70 i 486 if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ Err bitreich.org 70 i 487 (elm)->field.tqe_next->field.tqe_prev = \ Err bitreich.org 70 i 488 &(elm)->field.tqe_next; \ Err bitreich.org 70 i 489 else \ Err bitreich.org 70 i 490 (head)->tqh_last = &(elm)->field.tqe_next; \ Err bitreich.org 70 i 491 (listelm)->field.tqe_next = (elm); \ Err bitreich.org 70 i 492 (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ Err bitreich.org 70 i 493 } while (0) Err bitreich.org 70 i 494 Err bitreich.org 70 i 495 #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ Err bitreich.org 70 i 496 (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ Err bitreich.org 70 i 497 (elm)->field.tqe_next = (listelm); \ Err bitreich.org 70 i 498 *(listelm)->field.tqe_prev = (elm); \ Err bitreich.org 70 i 499 (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ Err bitreich.org 70 i 500 } while (0) Err bitreich.org 70 i 501 Err bitreich.org 70 i 502 #define TAILQ_REMOVE(head, elm, field) do { \ Err bitreich.org 70 i 503 if (((elm)->field.tqe_next) != NULL) \ Err bitreich.org 70 i 504 (elm)->field.tqe_next->field.tqe_prev = \ Err bitreich.org 70 i 505 (elm)->field.tqe_prev; \ Err bitreich.org 70 i 506 else \ Err bitreich.org 70 i 507 (head)->tqh_last = (elm)->field.tqe_prev; \ Err bitreich.org 70 i 508 *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ Err bitreich.org 70 i 509 _Q_INVALIDATE((elm)->field.tqe_prev); \ Err bitreich.org 70 i 510 _Q_INVALIDATE((elm)->field.tqe_next); \ Err bitreich.org 70 i 511 } while (0) Err bitreich.org 70 i 512 Err bitreich.org 70 i 513 #define TAILQ_REPLACE(head, elm, elm2, field) do { \ Err bitreich.org 70 i 514 if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ Err bitreich.org 70 i 515 (elm2)->field.tqe_next->field.tqe_prev = \ Err bitreich.org 70 i 516 &(elm2)->field.tqe_next; \ Err bitreich.org 70 i 517 else \ Err bitreich.org 70 i 518 (head)->tqh_last = &(elm2)->field.tqe_next; \ Err bitreich.org 70 i 519 (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ Err bitreich.org 70 i 520 *(elm2)->field.tqe_prev = (elm2); \ Err bitreich.org 70 i 521 _Q_INVALIDATE((elm)->field.tqe_prev); \ Err bitreich.org 70 i 522 _Q_INVALIDATE((elm)->field.tqe_next); \ Err bitreich.org 70 i 523 } while (0) Err bitreich.org 70 i 524 Err bitreich.org 70 i 525 #define TAILQ_CONCAT(head1, head2, field) do { \ Err bitreich.org 70 i 526 if (!TAILQ_EMPTY(head2)) { \ Err bitreich.org 70 i 527 *(head1)->tqh_last = (head2)->tqh_first; \ Err bitreich.org 70 i 528 (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ Err bitreich.org 70 i 529 (head1)->tqh_last = (head2)->tqh_last; \ Err bitreich.org 70 i 530 TAILQ_INIT((head2)); \ Err bitreich.org 70 i 531 } \ Err bitreich.org 70 i 532 } while (0) Err bitreich.org 70 i 533 Err bitreich.org 70 i 534 #endif /* !_SYS_QUEUE_H_ */ Err bitreich.org 70 .