memory/mozjemalloc/ql.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/memory/mozjemalloc/ql.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     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 +/*
    1.36 + * List definitions.
    1.37 + */
    1.38 +#define ql_head(a_type)							\
    1.39 +struct {								\
    1.40 +	a_type *qlh_first;						\
    1.41 +}
    1.42 +
    1.43 +#define ql_head_initializer(a_head) {NULL}
    1.44 +
    1.45 +#define ql_elm(a_type)	qr(a_type)
    1.46 +
    1.47 +/* List functions. */
    1.48 +#define ql_new(a_head) do {						\
    1.49 +	(a_head)->qlh_first = NULL;					\
    1.50 +} while (0)
    1.51 +
    1.52 +#define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field)
    1.53 +
    1.54 +#define ql_first(a_head) ((a_head)->qlh_first)
    1.55 +
    1.56 +#define ql_last(a_head, a_field)					\
    1.57 +	((ql_first(a_head) != NULL)					\
    1.58 +	    ? qr_prev(ql_first(a_head), a_field) : NULL)
    1.59 +
    1.60 +#define ql_next(a_head, a_elm, a_field)					\
    1.61 +	((ql_last(a_head, a_field) != (a_elm))				\
    1.62 +	    ? qr_next((a_elm), a_field)	: NULL)
    1.63 +
    1.64 +#define ql_prev(a_head, a_elm, a_field)					\
    1.65 +	((ql_first(a_head) != (a_elm)) ? qr_prev((a_elm), a_field)	\
    1.66 +				       : NULL)
    1.67 +
    1.68 +#define ql_before_insert(a_head, a_qlelm, a_elm, a_field) do {		\
    1.69 +	qr_before_insert((a_qlelm), (a_elm), a_field);			\
    1.70 +	if (ql_first(a_head) == (a_qlelm)) {				\
    1.71 +		ql_first(a_head) = (a_elm);				\
    1.72 +	}								\
    1.73 +} while (0)
    1.74 +
    1.75 +#define ql_after_insert(a_qlelm, a_elm, a_field)			\
    1.76 +	qr_after_insert((a_qlelm), (a_elm), a_field)
    1.77 +
    1.78 +#define ql_head_insert(a_head, a_elm, a_field) do {			\
    1.79 +	if (ql_first(a_head) != NULL) {					\
    1.80 +		qr_before_insert(ql_first(a_head), (a_elm), a_field);	\
    1.81 +	}								\
    1.82 +	ql_first(a_head) = (a_elm);					\
    1.83 +} while (0)
    1.84 +
    1.85 +#define ql_tail_insert(a_head, a_elm, a_field) do {			\
    1.86 +	if (ql_first(a_head) != NULL) {					\
    1.87 +		qr_before_insert(ql_first(a_head), (a_elm), a_field);	\
    1.88 +	}								\
    1.89 +	ql_first(a_head) = qr_next((a_elm), a_field);			\
    1.90 +} while (0)
    1.91 +
    1.92 +#define ql_remove(a_head, a_elm, a_field) do {				\
    1.93 +	if (ql_first(a_head) == (a_elm)) {				\
    1.94 +		ql_first(a_head) = qr_next(ql_first(a_head), a_field);	\
    1.95 +	}								\
    1.96 +	if (ql_first(a_head) != (a_elm)) {				\
    1.97 +		qr_remove((a_elm), a_field);				\
    1.98 +	} else {							\
    1.99 +		ql_first(a_head) = NULL;				\
   1.100 +	}								\
   1.101 +} while (0)
   1.102 +
   1.103 +#define ql_head_remove(a_head, a_type, a_field) do {			\
   1.104 +	a_type *t = ql_first(a_head);					\
   1.105 +	ql_remove((a_head), t, a_field);				\
   1.106 +} while (0)
   1.107 +
   1.108 +#define ql_tail_remove(a_head, a_type, a_field) do {			\
   1.109 +	a_type *t = ql_last(a_head, a_field);				\
   1.110 +	ql_remove((a_head), t, a_field);				\
   1.111 +} while (0)
   1.112 +
   1.113 +#define ql_foreach(a_var, a_head, a_field)				\
   1.114 +	qr_foreach((a_var), ql_first(a_head), a_field)
   1.115 +
   1.116 +#define ql_reverse_foreach(a_var, a_head, a_field)			\
   1.117 +	qr_reverse_foreach((a_var), ql_first(a_head), a_field)

mercurial