memory/mozjemalloc/qr.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /******************************************************************************
michael@0 2 *
michael@0 3 * Copyright (C) 2002 Jason Evans <jasone@canonware.com>.
michael@0 4 * All rights reserved.
michael@0 5 *
michael@0 6 * Redistribution and use in source and binary forms, with or without
michael@0 7 * modification, are permitted provided that the following conditions
michael@0 8 * are met:
michael@0 9 * 1. Redistributions of source code must retain the above copyright
michael@0 10 * notice(s), this list of conditions and the following disclaimer
michael@0 11 * unmodified other than the allowable addition of one or more
michael@0 12 * copyright notices.
michael@0 13 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 14 * notice(s), this list of conditions and the following disclaimer in
michael@0 15 * the documentation and/or other materials provided with the
michael@0 16 * distribution.
michael@0 17 *
michael@0 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
michael@0 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
michael@0 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
michael@0 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
michael@0 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
michael@0 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
michael@0 25 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
michael@0 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
michael@0 27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
michael@0 28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29 *
michael@0 30 ******************************************************************************/
michael@0 31
michael@0 32 /* Ring definitions. */
michael@0 33 #define qr(a_type) \
michael@0 34 struct { \
michael@0 35 a_type *qre_next; \
michael@0 36 a_type *qre_prev; \
michael@0 37 }
michael@0 38
michael@0 39 /* Ring functions. */
michael@0 40 #define qr_new(a_qr, a_field) do { \
michael@0 41 (a_qr)->a_field.qre_next = (a_qr); \
michael@0 42 (a_qr)->a_field.qre_prev = (a_qr); \
michael@0 43 } while (0)
michael@0 44
michael@0 45 #define qr_next(a_qr, a_field) ((a_qr)->a_field.qre_next)
michael@0 46
michael@0 47 #define qr_prev(a_qr, a_field) ((a_qr)->a_field.qre_prev)
michael@0 48
michael@0 49 #define qr_before_insert(a_qrelm, a_qr, a_field) do { \
michael@0 50 (a_qr)->a_field.qre_prev = (a_qrelm)->a_field.qre_prev; \
michael@0 51 (a_qr)->a_field.qre_next = (a_qrelm); \
michael@0 52 (a_qr)->a_field.qre_prev->a_field.qre_next = (a_qr); \
michael@0 53 (a_qrelm)->a_field.qre_prev = (a_qr); \
michael@0 54 } while (0)
michael@0 55
michael@0 56 #define qr_after_insert(a_qrelm, a_qr, a_field) \
michael@0 57 do \
michael@0 58 { \
michael@0 59 (a_qr)->a_field.qre_next = (a_qrelm)->a_field.qre_next; \
michael@0 60 (a_qr)->a_field.qre_prev = (a_qrelm); \
michael@0 61 (a_qr)->a_field.qre_next->a_field.qre_prev = (a_qr); \
michael@0 62 (a_qrelm)->a_field.qre_next = (a_qr); \
michael@0 63 } while (0)
michael@0 64
michael@0 65 #define qr_meld(a_qr_a, a_qr_b, a_field) do { \
michael@0 66 void *t; \
michael@0 67 (a_qr_a)->a_field.qre_prev->a_field.qre_next = (a_qr_b); \
michael@0 68 (a_qr_b)->a_field.qre_prev->a_field.qre_next = (a_qr_a); \
michael@0 69 t = (a_qr_a)->a_field.qre_prev; \
michael@0 70 (a_qr_a)->a_field.qre_prev = (a_qr_b)->a_field.qre_prev; \
michael@0 71 (a_qr_b)->a_field.qre_prev = t; \
michael@0 72 } while (0)
michael@0 73
michael@0 74 /* qr_meld() and qr_split() are functionally equivalent, so there's no need to
michael@0 75 * have two copies of the code. */
michael@0 76 #define qr_split(a_qr_a, a_qr_b, a_field) \
michael@0 77 qr_meld((a_qr_a), (a_qr_b), a_field)
michael@0 78
michael@0 79 #define qr_remove(a_qr, a_field) do { \
michael@0 80 (a_qr)->a_field.qre_prev->a_field.qre_next \
michael@0 81 = (a_qr)->a_field.qre_next; \
michael@0 82 (a_qr)->a_field.qre_next->a_field.qre_prev \
michael@0 83 = (a_qr)->a_field.qre_prev; \
michael@0 84 (a_qr)->a_field.qre_next = (a_qr); \
michael@0 85 (a_qr)->a_field.qre_prev = (a_qr); \
michael@0 86 } while (0)
michael@0 87
michael@0 88 #define qr_foreach(var, a_qr, a_field) \
michael@0 89 for ((var) = (a_qr); \
michael@0 90 (var) != NULL; \
michael@0 91 (var) = (((var)->a_field.qre_next != (a_qr)) \
michael@0 92 ? (var)->a_field.qre_next : NULL))
michael@0 93
michael@0 94 #define qr_reverse_foreach(var, a_qr, a_field) \
michael@0 95 for ((var) = ((a_qr) != NULL) ? qr_prev(a_qr, a_field) : NULL; \
michael@0 96 (var) != NULL; \
michael@0 97 (var) = (((var) != (a_qr)) \
michael@0 98 ? (var)->a_field.qre_prev : NULL))

mercurial