4
#include "types.h" // container_of
7
/****************************************************************
8
* hlist - Double linked lists with a single pointer list head
9
****************************************************************/
12
struct hlist_node *next, **pprev;
16
struct hlist_node *first;
20
hlist_empty(const struct hlist_head *h)
26
hlist_del(struct hlist_node *n)
28
struct hlist_node *next = n->next;
29
struct hlist_node **pprev = n->pprev;
36
hlist_add(struct hlist_node *n, struct hlist_node **pprev)
38
struct hlist_node *next = *pprev;
42
next->pprev = &n->next;
47
hlist_add_head(struct hlist_node *n, struct hlist_head *h)
49
hlist_add(n, &h->first);
53
hlist_add_before(struct hlist_node *n, struct hlist_node *next)
55
hlist_add(n, next->pprev);
59
hlist_add_after(struct hlist_node *n, struct hlist_node *prev)
61
hlist_add(n, &prev->next);
65
hlist_replace(struct hlist_node *old, struct hlist_node *new)
67
new->next = old->next;
69
new->next->pprev = &new->next;
70
new->pprev = old->pprev;
74
#define hlist_for_each_entry(pos, head, member) \
75
for (pos = container_of((head)->first, typeof(*pos), member) \
76
; pos != container_of(NULL, typeof(*pos), member) \
77
; pos = container_of(pos->member.next, typeof(*pos), member))
79
#define hlist_for_each_entry_safe(pos, n, head, member) \
80
for (pos = container_of((head)->first, typeof(*pos), member) \
81
; pos != container_of(NULL, typeof(*pos), member) \
82
&& ({ n = pos->member.next; 1; }) \
83
; pos = container_of(n, typeof(*pos), member))
85
#define hlist_for_each_entry_pprev(pos, pprev, head, member) \
86
for (pprev = &(head)->first \
87
; *pprev && ({ pos=container_of(*pprev, typeof(*pos), member); 1; }) \
88
; pprev = &(*pprev)->next)