1.链表结构体
struct list_head{
struct list_head *next;
stuct list_head *prev;
}
2.list_entry
#define container_of(ptr, type, member)\
container_of(ptr, type, member)
//ptr为list_head指针,type为包含list_head结构体对象类型,
//member为链表结构体变量名
3.链表初始化
INIT_LIST_HEAD()
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
static inline void INIT_LIST_HEAD(struct list_head *list)
{
WRITE_ONCE(list->next, list);
list->prev = list;
}
4.链表操作
list_add(sturct list_head *new, struct list_head *head)
//head 前加入new( 栈)
list_add_tail(sturct list_head *new, struct list_head *head)
//head后加入new(队列)
list_del(struct list_head *entry)
//不删除entry数据结构
list_move(struct list_head *list, struct list_head *head)
//list移除加到head后面
list_move_tail(struct list_head *list, struct list_head *head)
//list移除加到head前面
list_empty(struct list_head *head)
//链表是否为空
list_splice(struct list_head *list, struct list_head *head)
//连接两个链表
5.遍历链表
list_for_each(pos,head)
//pos遍历当前position,head链表头
list_for_each_entry(pos, head, member)
//pos为包含list_head节点对象的指针,head为头节点指针,member为pos中list_head结构变
//量名
list_for_each_entry_reverse(pos, head, member)
//反向遍历
list_for_each_entry_safe(pos, next, head, member)
list_for_each_entry_safe_reverse(pos, next, head, member)
//next与pos类型一致