media/libnestegg/src/hlist.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright (c) 2004-2010 Alex Pankratov. All rights reserved.
michael@0 3 *
michael@0 4 * Hierarchical memory allocator, 1.2.1
michael@0 5 * http://swapped.cc/halloc
michael@0 6 */
michael@0 7
michael@0 8 /*
michael@0 9 * The program is distributed under terms of BSD license.
michael@0 10 * You can obtain the copy of the license by visiting:
michael@0 11 *
michael@0 12 * http://www.opensource.org/licenses/bsd-license.php
michael@0 13 */
michael@0 14
michael@0 15 #ifndef _LIBP_HLIST_H_
michael@0 16 #define _LIBP_HLIST_H_
michael@0 17
michael@0 18 #include <assert.h>
michael@0 19 #include "macros.h" /* static_inline */
michael@0 20
michael@0 21 /*
michael@0 22 * weak double-linked list w/ tail sentinel
michael@0 23 */
michael@0 24 typedef struct hlist_head hlist_head_t;
michael@0 25 typedef struct hlist_item hlist_item_t;
michael@0 26
michael@0 27 /*
michael@0 28 *
michael@0 29 */
michael@0 30 struct hlist_head
michael@0 31 {
michael@0 32 hlist_item_t * next;
michael@0 33 };
michael@0 34
michael@0 35 struct hlist_item
michael@0 36 {
michael@0 37 hlist_item_t * next;
michael@0 38 hlist_item_t ** prev;
michael@0 39 };
michael@0 40
michael@0 41 /*
michael@0 42 * shared tail sentinel
michael@0 43 */
michael@0 44 struct hlist_item hlist_null;
michael@0 45
michael@0 46 /*
michael@0 47 *
michael@0 48 */
michael@0 49 #define __hlist_init(h) { &hlist_null }
michael@0 50 #define __hlist_init_item(i) { &hlist_null, &(i).next }
michael@0 51
michael@0 52 static_inline void hlist_init(hlist_head_t * h);
michael@0 53 static_inline void hlist_init_item(hlist_item_t * i);
michael@0 54
michael@0 55 /* static_inline void hlist_purge(hlist_head_t * h); */
michael@0 56
michael@0 57 /* static_inline bool_t hlist_empty(const hlist_head_t * h); */
michael@0 58
michael@0 59 /* static_inline hlist_item_t * hlist_head(const hlist_head_t * h); */
michael@0 60
michael@0 61 /* static_inline hlist_item_t * hlist_next(const hlist_item_t * i); */
michael@0 62 /* static_inline hlist_item_t * hlist_prev(const hlist_item_t * i,
michael@0 63 const hlist_head_t * h); */
michael@0 64
michael@0 65 static_inline void hlist_add(hlist_head_t * h, hlist_item_t * i);
michael@0 66
michael@0 67 /* static_inline void hlist_add_prev(hlist_item_t * l, hlist_item_t * i); */
michael@0 68 /* static_inline void hlist_add_next(hlist_item_t * l, hlist_item_t * i); */
michael@0 69
michael@0 70 static_inline void hlist_del(hlist_item_t * i);
michael@0 71
michael@0 72 static_inline void hlist_relink(hlist_item_t * i);
michael@0 73 static_inline void hlist_relink_head(hlist_head_t * h);
michael@0 74
michael@0 75 #define hlist_for_each(i, h) \
michael@0 76 for (i = (h)->next; i != &hlist_null; i = i->next)
michael@0 77
michael@0 78 #define hlist_for_each_safe(i, tmp, h) \
michael@0 79 for (i = (h)->next, tmp = i->next; \
michael@0 80 i!= &hlist_null; \
michael@0 81 i = tmp, tmp = i->next)
michael@0 82
michael@0 83 /*
michael@0 84 * static
michael@0 85 */
michael@0 86 static_inline void hlist_init(hlist_head_t * h)
michael@0 87 {
michael@0 88 assert(h);
michael@0 89 h->next = &hlist_null;
michael@0 90 }
michael@0 91
michael@0 92 static_inline void hlist_init_item(hlist_item_t * i)
michael@0 93 {
michael@0 94 assert(i);
michael@0 95 i->prev = &i->next;
michael@0 96 i->next = &hlist_null;
michael@0 97 }
michael@0 98
michael@0 99 static_inline void hlist_add(hlist_head_t * h, hlist_item_t * i)
michael@0 100 {
michael@0 101 hlist_item_t * next;
michael@0 102 assert(h && i);
michael@0 103
michael@0 104 next = i->next = h->next;
michael@0 105 next->prev = &i->next;
michael@0 106 h->next = i;
michael@0 107 i->prev = &h->next;
michael@0 108 }
michael@0 109
michael@0 110 static_inline void hlist_del(hlist_item_t * i)
michael@0 111 {
michael@0 112 hlist_item_t * next;
michael@0 113 assert(i);
michael@0 114
michael@0 115 next = i->next;
michael@0 116 next->prev = i->prev;
michael@0 117 *i->prev = next;
michael@0 118
michael@0 119 hlist_init_item(i);
michael@0 120 }
michael@0 121
michael@0 122 static_inline void hlist_relink(hlist_item_t * i)
michael@0 123 {
michael@0 124 assert(i);
michael@0 125 *i->prev = i;
michael@0 126 i->next->prev = &i->next;
michael@0 127 }
michael@0 128
michael@0 129 static_inline void hlist_relink_head(hlist_head_t * h)
michael@0 130 {
michael@0 131 assert(h);
michael@0 132 h->next->prev = &h->next;
michael@0 133 }
michael@0 134
michael@0 135 #endif
michael@0 136

mercurial