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.
23 struct cds_hlist_node
*next
;
28 struct cds_hlist_node
*next
;
29 struct cds_hlist_node
*prev
;
32 /* Initialize a new list head. */
33 static inline void CDS_INIT_HLIST_HEAD(struct cds_hlist_head
*ptr
)
38 /* Get typed element from list at a given position. */
39 #define cds_hlist_entry(ptr, type, member) \
40 ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
42 /* Add new element at the head of the list. */
43 static inline void cds_hlist_add_head (struct cds_hlist_node
*newp
,
44 struct cds_hlist_head
*head
)
47 head
->next
->prev
= newp
;
49 newp
->next
= head
->next
;
50 newp
->prev
= (struct cds_hlist_node
*)head
;
54 /* Remove element from list. */
55 static inline void cds_hlist_del (struct cds_hlist_node
*elem
)
58 elem
->next
->prev
= elem
->prev
;
60 elem
->prev
->next
= elem
->next
;
63 #define cds_hlist_for_each_entry(entry, pos, head, member) \
64 for (pos = (head)->next, \
65 entry = cds_hlist_entry(pos, __typeof__(*entry), member); \
68 entry = cds_hlist_entry(pos, __typeof__(*entry), member))
70 #define cds_hlist_for_each_entry_safe(entry, pos, p, head, member) \
71 for (pos = (head)->next, \
72 entry = cds_hlist_entry(pos, __typeof__(*entry), member); \
73 (pos != NULL) && ({ p = pos->next; 1;}); \
75 entry = cds_hlist_entry(pos, __typeof__(*entry), member))
77 #endif /* _KCOMPAT_HLIST_H */
This page took 0.029971 seconds and 4 git commands to generate.