1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libnestegg/src/hlist.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 1.4 +/* 1.5 + * Copyright (c) 2004-2010 Alex Pankratov. All rights reserved. 1.6 + * 1.7 + * Hierarchical memory allocator, 1.2.1 1.8 + * http://swapped.cc/halloc 1.9 + */ 1.10 + 1.11 +/* 1.12 + * The program is distributed under terms of BSD license. 1.13 + * You can obtain the copy of the license by visiting: 1.14 + * 1.15 + * http://www.opensource.org/licenses/bsd-license.php 1.16 + */ 1.17 + 1.18 +#ifndef _LIBP_HLIST_H_ 1.19 +#define _LIBP_HLIST_H_ 1.20 + 1.21 +#include <assert.h> 1.22 +#include "macros.h" /* static_inline */ 1.23 + 1.24 +/* 1.25 + * weak double-linked list w/ tail sentinel 1.26 + */ 1.27 +typedef struct hlist_head hlist_head_t; 1.28 +typedef struct hlist_item hlist_item_t; 1.29 + 1.30 +/* 1.31 + * 1.32 + */ 1.33 +struct hlist_head 1.34 +{ 1.35 + hlist_item_t * next; 1.36 +}; 1.37 + 1.38 +struct hlist_item 1.39 +{ 1.40 + hlist_item_t * next; 1.41 + hlist_item_t ** prev; 1.42 +}; 1.43 + 1.44 +/* 1.45 + * shared tail sentinel 1.46 + */ 1.47 +struct hlist_item hlist_null; 1.48 + 1.49 +/* 1.50 + * 1.51 + */ 1.52 +#define __hlist_init(h) { &hlist_null } 1.53 +#define __hlist_init_item(i) { &hlist_null, &(i).next } 1.54 + 1.55 +static_inline void hlist_init(hlist_head_t * h); 1.56 +static_inline void hlist_init_item(hlist_item_t * i); 1.57 + 1.58 +/* static_inline void hlist_purge(hlist_head_t * h); */ 1.59 + 1.60 +/* static_inline bool_t hlist_empty(const hlist_head_t * h); */ 1.61 + 1.62 +/* static_inline hlist_item_t * hlist_head(const hlist_head_t * h); */ 1.63 + 1.64 +/* static_inline hlist_item_t * hlist_next(const hlist_item_t * i); */ 1.65 +/* static_inline hlist_item_t * hlist_prev(const hlist_item_t * i, 1.66 + const hlist_head_t * h); */ 1.67 + 1.68 +static_inline void hlist_add(hlist_head_t * h, hlist_item_t * i); 1.69 + 1.70 +/* static_inline void hlist_add_prev(hlist_item_t * l, hlist_item_t * i); */ 1.71 +/* static_inline void hlist_add_next(hlist_item_t * l, hlist_item_t * i); */ 1.72 + 1.73 +static_inline void hlist_del(hlist_item_t * i); 1.74 + 1.75 +static_inline void hlist_relink(hlist_item_t * i); 1.76 +static_inline void hlist_relink_head(hlist_head_t * h); 1.77 + 1.78 +#define hlist_for_each(i, h) \ 1.79 + for (i = (h)->next; i != &hlist_null; i = i->next) 1.80 + 1.81 +#define hlist_for_each_safe(i, tmp, h) \ 1.82 + for (i = (h)->next, tmp = i->next; \ 1.83 + i!= &hlist_null; \ 1.84 + i = tmp, tmp = i->next) 1.85 + 1.86 +/* 1.87 + * static 1.88 + */ 1.89 +static_inline void hlist_init(hlist_head_t * h) 1.90 +{ 1.91 + assert(h); 1.92 + h->next = &hlist_null; 1.93 +} 1.94 + 1.95 +static_inline void hlist_init_item(hlist_item_t * i) 1.96 +{ 1.97 + assert(i); 1.98 + i->prev = &i->next; 1.99 + i->next = &hlist_null; 1.100 +} 1.101 + 1.102 +static_inline void hlist_add(hlist_head_t * h, hlist_item_t * i) 1.103 +{ 1.104 + hlist_item_t * next; 1.105 + assert(h && i); 1.106 + 1.107 + next = i->next = h->next; 1.108 + next->prev = &i->next; 1.109 + h->next = i; 1.110 + i->prev = &h->next; 1.111 +} 1.112 + 1.113 +static_inline void hlist_del(hlist_item_t * i) 1.114 +{ 1.115 + hlist_item_t * next; 1.116 + assert(i); 1.117 + 1.118 + next = i->next; 1.119 + next->prev = i->prev; 1.120 + *i->prev = next; 1.121 + 1.122 + hlist_init_item(i); 1.123 +} 1.124 + 1.125 +static_inline void hlist_relink(hlist_item_t * i) 1.126 +{ 1.127 + assert(i); 1.128 + *i->prev = i; 1.129 + i->next->prev = &i->next; 1.130 +} 1.131 + 1.132 +static_inline void hlist_relink_head(hlist_head_t * h) 1.133 +{ 1.134 + assert(h); 1.135 + h->next->prev = &h->next; 1.136 +} 1.137 + 1.138 +#endif 1.139 +