Linux-2.6驱动开发 2 列表

本文详细介绍了Linux内核中list.h文件中的数据结构list_head及其相关操作函数,包括初始化、遍历、插入、删除等,并解释了如何使用这些函数来管理和遍历链表。

文件位置:include/linux/list.h

数据结构:

struct list_head {

       struct list_head *next, *prev;

};

操作:

LIST_HEAD(name);

name定义成上面的数据结构,同时next,prev都指向起始位置。

list_entry(ptr, type, member);

返回list_head的父结构体地址。其中ptr 是所求父结构体中list_head成员指针,type是所求父结构体类型,memberlist_head成员名。

list_first_entry(ptr, type, member);

获取指定list_head结构体成员地址指向的next的父结构体地址。其中ptr 是所求结构体中list_head成员指针,type是所求结构体类型,member是结构体list_head成员名。

list_for_each(pos, head)

       向下遍历;是一个for(;;)结构体,没有结束的。使用方法

list_for_each(pos, head)

{

      

}

Pos是一个list_head变量,相当于int i;for(i=0;i<4;i++) 中的i;

Head是一个要遍历的list_head头。

__list_for_each(pos, head)

同上,区别:没prefetch操作,快。

list_for_each_prev(pos, head)

向下遍历;Pos是一个list_head变量,相当于int i;for(i=0;i<4;i++) 中的i;

Head是一个要遍历的list_head头。

list_for_each_safe(pos, n, head)

   向下遍历,同list_for_each,区别:pos可以初修改。n也是一个list_head变量

list_for_each_prev_safe(pos, n, head)

   向上遍历,同list_for_each_prev,区别:pos可以初修改。n也是一个list_head变量

list_for_each_entry(pos, head, member)

   向下遍历list_head的父结构。Pos是一个list_head变量,member 名称

list_for_each_entry_reverse(pos, head, member)

   向上遍历list_head的父结构。

list_prepare_entry(pos, head, member)

   判断pos是有已指定,若已指定则无操作,否则将head的父结构地址返回。

 

list_for_each_entry_continue(pos, head, member)

list_for_each_entry_continue_reverse (pos, head, member)

list_for_each_entry_from(pos, head, member)

list_for_each_entry_safe(pos, n, head, member)

list_for_each_entry_safe_continue(pos, n, head, member)

list_for_each_entry_safe_from(pos, n, head, member)

list_for_each_entry_safe_reverse(pos, n, head, member)

 

list_add(struct list_head *new, struct list_head *head)

new 插在前面

list_add_tail (struct list_head *new, struct list_head *head)

   new 插在后面

list_del(struct list_head *entry)

   删除entry结点

list_replace(struct list_head *old,struct list_head *new)

   替换

list_replace_init (struct list_head *old,  struct list_head *new)

   替换初始结点

list_del_init(struct list_head *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_is_last(const struct list_head *list, const struct list_head *head)

  判断是否头

int list_empty(const struct list_head *head)

  判断是否空

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值