list_entry和list_for_each分析
来源:互联网 发布:卡尔曼滤波融合算法 编辑:程序博客网 时间:2024/05/01 17:08
百度了一些文章,关于list_entry的解释都不甚清楚,故google了一下,找到一个解释挺好,故翻译一下
list_entry:
#define list_entry(ptr, type, member)
简单来说,比如有两个数据结构:
struct data { int something;}struct container { int something_before; struct data data_item; int something_after;}假设你有一个指针ptr指向data,执行下面语句之后,指针cont_ptr所指向的结构会包含ptr所指向的结构,相当于宏list_entry做了一次指针转换并赋值
struct container *cont_ptr = list_entry(data_ptr, struct container, data_item)
原理:宏list_entry会计算data_item在结构container内的位置,并获取指针data_ptr的内容复制到结构container内相应位置。
list_for_each:
/** * list_for_each iterate over a list * @pos: the &struct list_head to use as a loop cursor. * @head: the head for your list. */ #define list_for_each(pos, head) \ for (pos = (head)->next; pos != (head); pos = pos->next)
从定义中易知,宏list_for_each就是用于循环遍历,指针从链表head的下一个位置开始遍历,直到遍历到头指针。
0 0
- list_entry和list_for_each分析
- list_for_each 分析
- Linux内核中list_head、list_for_each、list_entry、container_of之间的关系
- list_for_each & list_entry & 对内核链表的理解
- list_for_each
- 内核list_entry宏分析
- 详解Linux内核之双向循环链表(2) list_for_each/list_entry/list_for_each_entry
- list_head和list_entry学习
- list_head和list_entry
- list_entry和list_for_each_entry
- list_entry
- list_entry
- list_entry
- list_entry
- list_entry
- LIST_ENTRY
- list_entry()
- list_entry()
- android实现记住用户名和密码以及实现自动登录
- uml类图关系
- 一个用 C++ 实现的快速无锁队列
- 浙大PAT考试1005~1008
- 两表连接
- list_entry和list_for_each分析
- struct inode和struct file
- 以太网及IEEE802封装
- Spring注解大全以及案例
- RO段、RW段和ZI段 说明
- 聪明的哥在出租车巧设免费WiFi
- 普林斯顿公开课 算法3-2:求第k大的数
- OSI模型
- Android 驱动 (一) GPIO