1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/memory/mozjemalloc/qr.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +/****************************************************************************** 1.5 + * 1.6 + * Copyright (C) 2002 Jason Evans <jasone@canonware.com>. 1.7 + * All rights reserved. 1.8 + * 1.9 + * Redistribution and use in source and binary forms, with or without 1.10 + * modification, are permitted provided that the following conditions 1.11 + * are met: 1.12 + * 1. Redistributions of source code must retain the above copyright 1.13 + * notice(s), this list of conditions and the following disclaimer 1.14 + * unmodified other than the allowable addition of one or more 1.15 + * copyright notices. 1.16 + * 2. Redistributions in binary form must reproduce the above copyright 1.17 + * notice(s), this list of conditions and the following disclaimer in 1.18 + * the documentation and/or other materials provided with the 1.19 + * distribution. 1.20 + * 1.21 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 1.22 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.23 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.24 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 1.25 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.26 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.27 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 1.28 + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 1.29 + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 1.30 + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 1.31 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.32 + * 1.33 + ******************************************************************************/ 1.34 + 1.35 +/* Ring definitions. */ 1.36 +#define qr(a_type) \ 1.37 +struct { \ 1.38 + a_type *qre_next; \ 1.39 + a_type *qre_prev; \ 1.40 +} 1.41 + 1.42 +/* Ring functions. */ 1.43 +#define qr_new(a_qr, a_field) do { \ 1.44 + (a_qr)->a_field.qre_next = (a_qr); \ 1.45 + (a_qr)->a_field.qre_prev = (a_qr); \ 1.46 +} while (0) 1.47 + 1.48 +#define qr_next(a_qr, a_field) ((a_qr)->a_field.qre_next) 1.49 + 1.50 +#define qr_prev(a_qr, a_field) ((a_qr)->a_field.qre_prev) 1.51 + 1.52 +#define qr_before_insert(a_qrelm, a_qr, a_field) do { \ 1.53 + (a_qr)->a_field.qre_prev = (a_qrelm)->a_field.qre_prev; \ 1.54 + (a_qr)->a_field.qre_next = (a_qrelm); \ 1.55 + (a_qr)->a_field.qre_prev->a_field.qre_next = (a_qr); \ 1.56 + (a_qrelm)->a_field.qre_prev = (a_qr); \ 1.57 +} while (0) 1.58 + 1.59 +#define qr_after_insert(a_qrelm, a_qr, a_field) \ 1.60 + do \ 1.61 + { \ 1.62 + (a_qr)->a_field.qre_next = (a_qrelm)->a_field.qre_next; \ 1.63 + (a_qr)->a_field.qre_prev = (a_qrelm); \ 1.64 + (a_qr)->a_field.qre_next->a_field.qre_prev = (a_qr); \ 1.65 + (a_qrelm)->a_field.qre_next = (a_qr); \ 1.66 + } while (0) 1.67 + 1.68 +#define qr_meld(a_qr_a, a_qr_b, a_field) do { \ 1.69 + void *t; \ 1.70 + (a_qr_a)->a_field.qre_prev->a_field.qre_next = (a_qr_b); \ 1.71 + (a_qr_b)->a_field.qre_prev->a_field.qre_next = (a_qr_a); \ 1.72 + t = (a_qr_a)->a_field.qre_prev; \ 1.73 + (a_qr_a)->a_field.qre_prev = (a_qr_b)->a_field.qre_prev; \ 1.74 + (a_qr_b)->a_field.qre_prev = t; \ 1.75 +} while (0) 1.76 + 1.77 +/* qr_meld() and qr_split() are functionally equivalent, so there's no need to 1.78 + * have two copies of the code. */ 1.79 +#define qr_split(a_qr_a, a_qr_b, a_field) \ 1.80 + qr_meld((a_qr_a), (a_qr_b), a_field) 1.81 + 1.82 +#define qr_remove(a_qr, a_field) do { \ 1.83 + (a_qr)->a_field.qre_prev->a_field.qre_next \ 1.84 + = (a_qr)->a_field.qre_next; \ 1.85 + (a_qr)->a_field.qre_next->a_field.qre_prev \ 1.86 + = (a_qr)->a_field.qre_prev; \ 1.87 + (a_qr)->a_field.qre_next = (a_qr); \ 1.88 + (a_qr)->a_field.qre_prev = (a_qr); \ 1.89 +} while (0) 1.90 + 1.91 +#define qr_foreach(var, a_qr, a_field) \ 1.92 + for ((var) = (a_qr); \ 1.93 + (var) != NULL; \ 1.94 + (var) = (((var)->a_field.qre_next != (a_qr)) \ 1.95 + ? (var)->a_field.qre_next : NULL)) 1.96 + 1.97 +#define qr_reverse_foreach(var, a_qr, a_field) \ 1.98 + for ((var) = ((a_qr) != NULL) ? qr_prev(a_qr, a_field) : NULL; \ 1.99 + (var) != NULL; \ 1.100 + (var) = (((var) != (a_qr)) \ 1.101 + ? (var)->a_field.qre_prev : NULL))