1 #ifndef _KCOMPAT_HLIST_H
2 #define _KCOMPAT_HLIST_H
5 * Kernel sourcecode compatible lightweight single pointer list head useful
6 * for implementing hash tables
8 * Copyright (C) 2009 Novell Inc.
10 * Author: Jan Blunck <jblunck@suse.de>
12 * Copyright (C) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU Lesser General Public License version 2.1 as
16 * published by the Free Software Foundation.
21 struct hlist_node
*next
;
26 struct hlist_node
*next
;
27 struct hlist_node
*prev
;
30 /* Initialize a new list head. */
31 static inline void INIT_HLIST_HEAD(struct hlist_head
*ptr
)
36 /* Get typed element from list at a given position. */
37 #define hlist_entry(ptr, type, member) \
38 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
40 /* Add new element at the head of the list. */
41 static inline void hlist_add_head (struct hlist_node
*newp
,
42 struct hlist_head
*head
)
45 head
->next
->prev
= newp
;
47 newp
->next
= head
->next
;
48 newp
->prev
= (struct hlist_node
*)head
;
52 /* Remove element from list. */
53 static inline void hlist_del (struct hlist_node
*elem
)
56 elem
->next
->prev
= elem
->prev
;
58 elem
->prev
->next
= elem
->next
;
61 #define hlist_for_each_entry(entry, pos, head, member) \
62 for (pos = (head)->next, \
63 entry = hlist_entry(pos, typeof(*entry), member); \
66 entry = hlist_entry(pos, typeof(*entry), member))
68 #define hlist_for_each_entry_safe(entry, pos, p, head, member) \
69 for (pos = (head)->next, \
70 entry = hlist_entry(pos, typeof(*entry), member); \
71 (pos != NULL) && ({ p = pos->next; 1;}); \
73 entry = hlist_entry(pos, typeof(*entry), member))
75 #endif /* _KCOMPAT_HLIST_H */
This page took 0.031055 seconds and 4 git commands to generate.