2 * Copyright (c) 2004-2010 Alex Pankratov. All rights reserved.
4 * Hierarchical memory allocator, 1.2.1
5 * http://swapped.cc/halloc
9 * The program is distributed under terms of BSD license.
10 * You can obtain the copy of the license by visiting:
12 * http://www.opensource.org/licenses/bsd-license.php
15 #ifndef _LIBP_HLIST_H_
16 #define _LIBP_HLIST_H_
19 #include "macros.h" /* static_inline */
22 * weak double-linked list w/ tail sentinel
24 typedef struct hlist_head hlist_head_t
;
25 typedef struct hlist_item hlist_item_t
;
42 * shared tail sentinel
44 struct hlist_item hlist_null
;
49 #define __hlist_init(h) { &hlist_null }
50 #define __hlist_init_item(i) { &hlist_null, &(i).next }
52 static_inline
void hlist_init(hlist_head_t
* h
);
53 static_inline
void hlist_init_item(hlist_item_t
* i
);
55 /* static_inline void hlist_purge(hlist_head_t * h); */
57 /* static_inline bool_t hlist_empty(const hlist_head_t * h); */
59 /* static_inline hlist_item_t * hlist_head(const hlist_head_t * h); */
61 /* static_inline hlist_item_t * hlist_next(const hlist_item_t * i); */
62 /* static_inline hlist_item_t * hlist_prev(const hlist_item_t * i,
63 const hlist_head_t * h); */
65 static_inline
void hlist_add(hlist_head_t
* h
, hlist_item_t
* i
);
67 /* static_inline void hlist_add_prev(hlist_item_t * l, hlist_item_t * i); */
68 /* static_inline void hlist_add_next(hlist_item_t * l, hlist_item_t * i); */
70 static_inline
void hlist_del(hlist_item_t
* i
);
72 static_inline
void hlist_relink(hlist_item_t
* i
);
73 static_inline
void hlist_relink_head(hlist_head_t
* h
);
75 #define hlist_for_each(i, h) \
76 for (i = (h)->next; i != &hlist_null; i = i->next)
78 #define hlist_for_each_safe(i, tmp, h) \
79 for (i = (h)->next, tmp = i->next; \
81 i = tmp, tmp = i->next)
86 static_inline
void hlist_init(hlist_head_t
* h
)
89 h
->next
= &hlist_null
;
92 static_inline
void hlist_init_item(hlist_item_t
* i
)
96 i
->next
= &hlist_null
;
99 static_inline
void hlist_add(hlist_head_t
* h
, hlist_item_t
* i
)
104 next
= i
->next
= h
->next
;
105 next
->prev
= &i
->next
;
110 static_inline
void hlist_del(hlist_item_t
* i
)
116 next
->prev
= i
->prev
;
122 static_inline
void hlist_relink(hlist_item_t
* i
)
126 i
->next
->prev
= &i
->next
;
129 static_inline
void hlist_relink_head(hlist_head_t
* h
)
132 h
->next
->prev
= &h
->next
;