Commit 4952b459 authored by Jiri Pirko's avatar Jiri Pirko Committed by Stephen Hemminger

include: add linked list implementation from kernel

Rename hlist.h to list.h while adding it to be aligned with kernel
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
parent 325d02b4
#ifndef __HLIST_H__
#define __HLIST_H__ 1
/* Hash list stuff from kernel */
#ifndef __LIST_H__
#define __LIST_H__ 1
/* List and hash list stuff from kernel */
#include <stddef.h>
......@@ -8,6 +8,62 @@
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
struct list_head {
struct list_head *next, *prev;
};
static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->next = list;
list->prev = list;
}
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
next->prev = prev;
prev->next = next;
}
static inline void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
}
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
#define list_first_entry(ptr, type, member) \
list_entry((ptr)->next, type, member)
#define list_next_entry(pos, member) \
list_entry((pos)->member.next, typeof(*(pos)), member)
#define list_for_each_entry(pos, head, member) \
for (pos = list_first_entry(head, typeof(*pos), member); \
&pos->member != (head); \
pos = list_next_entry(pos, member))
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_first_entry(head, typeof(*pos), member), \
n = list_next_entry(pos, member); \
&pos->member != (head); \
pos = n, n = list_next_entry(n, member))
struct hlist_head {
struct hlist_node *first;
};
......@@ -53,4 +109,4 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
pos; \
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
#endif /* __HLIST_H__ */
#endif /* __LIST_H__ */
......@@ -18,7 +18,7 @@
#include <linux/net_namespace.h>
#include "utils.h"
#include "hlist.h"
#include "list.h"
#include "ip_common.h"
#include "namespace.h"
......
......@@ -22,7 +22,7 @@
#include "libnetlink.h"
#include "ll_map.h"
#include "hlist.h"
#include "list.h"
struct ll_cache {
struct hlist_node idx_hash;
......
......@@ -24,7 +24,7 @@
#include "utils.h"
#include "tc_util.h"
#include "tc_common.h"
#include "hlist.h"
#include "list.h"
struct graph_node {
struct hlist_node hlist;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment