链表结构体,定义在<linux/types.h>中,如下:
struct list_head {
struct list_head *next, *prev;
};
这个结构通常是嵌入到别的结构体中来使用。
链表常用操作函数有:
1、链表静态初始化
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
2、链表动态初始化
static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->next = list;
list->prev = list;
}
3、在链表中添加一个节点(在head节点后插入一个new节点)
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
该函数可以用来实现一个堆栈(先进后出)。
static inline vo