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 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License version 2.1 as
14 * published by the Free Software Foundation.
19 struct hlist_node
*next
;
24 struct hlist_node
*next
;
25 struct hlist_node
*prev
;
28 /* Initialize a new list head. */
29 static inline void INIT_HLIST_HEAD(struct hlist_head
*ptr
)
34 /* Get typed element from list at a given position. */
35 #define hlist_entry(ptr, type, member) \
36 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
38 /* Add new element at the head of the list. */
39 static inline void hlist_add_head (struct hlist_node
*newp
,
40 struct hlist_head
*head
)
43 head
->next
->prev
= newp
;
45 newp
->next
= head
->next
;
46 newp
->prev
= (struct hlist_node
*)head
;
50 /* Remove element from list. */
51 static inline void hlist_del (struct hlist_node
*elem
)
54 elem
->next
->prev
= elem
->prev
;
56 elem
->prev
->next
= elem
->next
;
59 #define hlist_for_each_entry(entry, pos, head, member) \
60 for (pos = (head)->next, \
61 entry = hlist_entry(pos, typeof(*entry), member); \
64 entry = hlist_entry(pos, typeof(*entry), member))
66 #define hlist_for_each_entry_safe(entry, pos, p, head, member) \
67 for (pos = (head)->next, \
68 entry = hlist_entry(pos, typeof(*entry), member); \
69 (pos != NULL) && ({ p = pos->next; 1;}); \
71 entry = hlist_entry(pos, typeof(*entry), member))
73 #endif /* _KCOMPAT_HLIST_H */
This page took 0.046702 seconds and 5 git commands to generate.