1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/memory/mozjemalloc/linkedlist.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +/* -*- Mode: C; tab-width: 8; c-basic-offset: 8; indent-tabs-mode: t -*- */ 1.5 +/* vim:set softtabstop=8 shiftwidth=8 noet: */ 1.6 +/*- 1.7 + * Copyright (C) the Mozilla Foundation. 1.8 + * All rights reserved. 1.9 + * 1.10 + * Redistribution and use in source and binary forms, with or without 1.11 + * modification, are permitted provided that the following conditions 1.12 + * are met: 1.13 + * 1. Redistributions of source code must retain the above copyright 1.14 + * notice(s), this list of conditions and the following disclaimer as 1.15 + * the first lines of this file unmodified other than the possible 1.16 + * addition of one or more copyright notices. 1.17 + * 2. Redistributions in binary form must reproduce the above copyright 1.18 + * notice(s), this list of conditions and the following disclaimer in 1.19 + * the documentation and/or other materials provided with the 1.20 + * distribution. 1.21 + * 1.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 1.23 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.24 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.25 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 1.26 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.27 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.28 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 1.29 + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 1.30 + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 1.31 + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 1.32 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.33 + * 1.34 + *******************************************************************************/ 1.35 + 1.36 +#ifndef linkedlist_h__ 1.37 +#define linkedlist_h__ 1.38 + 1.39 +#include <stddef.h> 1.40 + 1.41 +typedef struct LinkedList_s LinkedList; 1.42 + 1.43 +struct LinkedList_s { 1.44 + LinkedList *next; 1.45 + LinkedList *prev; 1.46 +}; 1.47 + 1.48 +/* Convert from LinkedList* to foo*. */ 1.49 +#define LinkedList_Get(e, type, prop) \ 1.50 + (type*)((char*)(e) - offsetof(type, prop)) 1.51 + 1.52 +/* Insert |e| at the beginning of |l|. */ 1.53 +void LinkedList_InsertHead(LinkedList *l, LinkedList *e) 1.54 +{ 1.55 + e->next = l; 1.56 + e->prev = l->prev; 1.57 + e->next->prev = e; 1.58 + e->prev->next = e; 1.59 +} 1.60 + 1.61 +void LinkedList_Remove(LinkedList *e) 1.62 +{ 1.63 + e->prev->next = e->next; 1.64 + e->next->prev = e->prev; 1.65 + e->next = e; 1.66 + e->prev = e; 1.67 +} 1.68 + 1.69 +bool LinkedList_IsEmpty(LinkedList *e) 1.70 +{ 1.71 + return e->next == e; 1.72 +} 1.73 + 1.74 +void LinkedList_Init(LinkedList *e) 1.75 +{ 1.76 + e->next = e; 1.77 + e->prev = e; 1.78 +} 1.79 + 1.80 +#endif