memory/mozjemalloc/ql.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 /*
michael@0 33 * List definitions.
michael@0 34 */
michael@0 35 #define ql_head(a_type) \
michael@0 36 struct { \
michael@0 37 a_type *qlh_first; \
michael@0 38 }
michael@0 39
michael@0 40 #define ql_head_initializer(a_head) {NULL}
michael@0 41
michael@0 42 #define ql_elm(a_type) qr(a_type)
michael@0 43
michael@0 44 /* List functions. */
michael@0 45 #define ql_new(a_head) do { \
michael@0 46 (a_head)->qlh_first = NULL; \
michael@0 47 } while (0)
michael@0 48
michael@0 49 #define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field)
michael@0 50
michael@0 51 #define ql_first(a_head) ((a_head)->qlh_first)
michael@0 52
michael@0 53 #define ql_last(a_head, a_field) \
michael@0 54 ((ql_first(a_head) != NULL) \
michael@0 55 ? qr_prev(ql_first(a_head), a_field) : NULL)
michael@0 56
michael@0 57 #define ql_next(a_head, a_elm, a_field) \
michael@0 58 ((ql_last(a_head, a_field) != (a_elm)) \
michael@0 59 ? qr_next((a_elm), a_field) : NULL)
michael@0 60
michael@0 61 #define ql_prev(a_head, a_elm, a_field) \
michael@0 62 ((ql_first(a_head) != (a_elm)) ? qr_prev((a_elm), a_field) \
michael@0 63 : NULL)
michael@0 64
michael@0 65 #define ql_before_insert(a_head, a_qlelm, a_elm, a_field) do { \
michael@0 66 qr_before_insert((a_qlelm), (a_elm), a_field); \
michael@0 67 if (ql_first(a_head) == (a_qlelm)) { \
michael@0 68 ql_first(a_head) = (a_elm); \
michael@0 69 } \
michael@0 70 } while (0)
michael@0 71
michael@0 72 #define ql_after_insert(a_qlelm, a_elm, a_field) \
michael@0 73 qr_after_insert((a_qlelm), (a_elm), a_field)
michael@0 74
michael@0 75 #define ql_head_insert(a_head, a_elm, a_field) do { \
michael@0 76 if (ql_first(a_head) != NULL) { \
michael@0 77 qr_before_insert(ql_first(a_head), (a_elm), a_field); \
michael@0 78 } \
michael@0 79 ql_first(a_head) = (a_elm); \
michael@0 80 } while (0)
michael@0 81
michael@0 82 #define ql_tail_insert(a_head, a_elm, a_field) do { \
michael@0 83 if (ql_first(a_head) != NULL) { \
michael@0 84 qr_before_insert(ql_first(a_head), (a_elm), a_field); \
michael@0 85 } \
michael@0 86 ql_first(a_head) = qr_next((a_elm), a_field); \
michael@0 87 } while (0)
michael@0 88
michael@0 89 #define ql_remove(a_head, a_elm, a_field) do { \
michael@0 90 if (ql_first(a_head) == (a_elm)) { \
michael@0 91 ql_first(a_head) = qr_next(ql_first(a_head), a_field); \
michael@0 92 } \
michael@0 93 if (ql_first(a_head) != (a_elm)) { \
michael@0 94 qr_remove((a_elm), a_field); \
michael@0 95 } else { \
michael@0 96 ql_first(a_head) = NULL; \
michael@0 97 } \
michael@0 98 } while (0)
michael@0 99
michael@0 100 #define ql_head_remove(a_head, a_type, a_field) do { \
michael@0 101 a_type *t = ql_first(a_head); \
michael@0 102 ql_remove((a_head), t, a_field); \
michael@0 103 } while (0)
michael@0 104
michael@0 105 #define ql_tail_remove(a_head, a_type, a_field) do { \
michael@0 106 a_type *t = ql_last(a_head, a_field); \
michael@0 107 ql_remove((a_head), t, a_field); \
michael@0 108 } while (0)
michael@0 109
michael@0 110 #define ql_foreach(a_var, a_head, a_field) \
michael@0 111 qr_foreach((a_var), ql_first(a_head), a_field)
michael@0 112
michael@0 113 #define ql_reverse_foreach(a_var, a_head, a_field) \
michael@0 114 qr_reverse_foreach((a_var), ql_first(a_head), a_field)

mercurial