memory/mozjemalloc/linkedlist.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 /* -*- Mode: C; tab-width: 8; c-basic-offset: 8; indent-tabs-mode: t -*- */
michael@0 2 /* vim:set softtabstop=8 shiftwidth=8 noet: */
michael@0 3 /*-
michael@0 4 * Copyright (C) the Mozilla Foundation.
michael@0 5 * All rights reserved.
michael@0 6 *
michael@0 7 * Redistribution and use in source and binary forms, with or without
michael@0 8 * modification, are permitted provided that the following conditions
michael@0 9 * are met:
michael@0 10 * 1. Redistributions of source code must retain the above copyright
michael@0 11 * notice(s), this list of conditions and the following disclaimer as
michael@0 12 * the first lines of this file unmodified other than the possible
michael@0 13 * addition of one or more copyright notices.
michael@0 14 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 15 * notice(s), this list of conditions and the following disclaimer in
michael@0 16 * the documentation and/or other materials provided with the
michael@0 17 * distribution.
michael@0 18 *
michael@0 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
michael@0 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
michael@0 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
michael@0 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
michael@0 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
michael@0 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
michael@0 26 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
michael@0 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
michael@0 28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
michael@0 29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 30 *
michael@0 31 *******************************************************************************/
michael@0 32
michael@0 33 #ifndef linkedlist_h__
michael@0 34 #define linkedlist_h__
michael@0 35
michael@0 36 #include <stddef.h>
michael@0 37
michael@0 38 typedef struct LinkedList_s LinkedList;
michael@0 39
michael@0 40 struct LinkedList_s {
michael@0 41 LinkedList *next;
michael@0 42 LinkedList *prev;
michael@0 43 };
michael@0 44
michael@0 45 /* Convert from LinkedList* to foo*. */
michael@0 46 #define LinkedList_Get(e, type, prop) \
michael@0 47 (type*)((char*)(e) - offsetof(type, prop))
michael@0 48
michael@0 49 /* Insert |e| at the beginning of |l|. */
michael@0 50 void LinkedList_InsertHead(LinkedList *l, LinkedList *e)
michael@0 51 {
michael@0 52 e->next = l;
michael@0 53 e->prev = l->prev;
michael@0 54 e->next->prev = e;
michael@0 55 e->prev->next = e;
michael@0 56 }
michael@0 57
michael@0 58 void LinkedList_Remove(LinkedList *e)
michael@0 59 {
michael@0 60 e->prev->next = e->next;
michael@0 61 e->next->prev = e->prev;
michael@0 62 e->next = e;
michael@0 63 e->prev = e;
michael@0 64 }
michael@0 65
michael@0 66 bool LinkedList_IsEmpty(LinkedList *e)
michael@0 67 {
michael@0 68 return e->next == e;
michael@0 69 }
michael@0 70
michael@0 71 void LinkedList_Init(LinkedList *e)
michael@0 72 {
michael@0 73 e->next = e;
michael@0 74 e->prev = e;
michael@0 75 }
michael@0 76
michael@0 77 #endif

mercurial