mirror of
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
synced 2024-11-17 15:03:29 +08:00
0025e5d63d
Make ll_ functions faster by having a name hash, and allow for deletion. Also, allow them to work without calling ll_init_map.
57 lines
1.3 KiB
C
57 lines
1.3 KiB
C
#ifndef __HLIST_H__
|
|
#define __HLIST_H__ 1
|
|
/* Hash list stuff from kernel */
|
|
|
|
#include <stddef.h>
|
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
|
|
|
struct hlist_head {
|
|
struct hlist_node *first;
|
|
};
|
|
|
|
struct hlist_node {
|
|
struct hlist_node *next, **pprev;
|
|
};
|
|
|
|
static inline void hlist_del(struct hlist_node *n)
|
|
{
|
|
struct hlist_node *next = n->next;
|
|
struct hlist_node **pprev = n->pprev;
|
|
*pprev = next;
|
|
if (next)
|
|
next->pprev = pprev;
|
|
}
|
|
|
|
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
|
{
|
|
struct hlist_node *first = h->first;
|
|
n->next = first;
|
|
if (first)
|
|
first->pprev = &n->next;
|
|
h->first = n;
|
|
n->pprev = &h->first;
|
|
}
|
|
|
|
#define hlist_for_each(pos, head) \
|
|
for (pos = (head)->first; pos ; pos = pos->next)
|
|
|
|
|
|
#define hlist_for_each_safe(pos, n, head) \
|
|
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
|
|
pos = n)
|
|
|
|
#define hlist_entry_safe(ptr, type, member) \
|
|
({ typeof(ptr) ____ptr = (ptr); \
|
|
____ptr ? hlist_entry(____ptr, type, member) : NULL; \
|
|
})
|
|
|
|
#define hlist_for_each_entry(pos, head, member) \
|
|
for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
|
|
pos; \
|
|
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
|
|
|
|
#endif /* __HLIST_H__ */
|