- 8
- 0
- 约7.34千字
- 约 6页
- 2017-06-07 发布于湖北
- 举报
list_for_each与list_for_each_entry详解??
一、list_for_each
1.list_for_each原型#define list_for_each(pos, head) \??? for (pos = (head)-next, prefetch(pos-next); pos != (head); \??? pos = pos-next, prefetch(pos-next))它实际上是一个 for 循环,利用传入的pos 作为循环变量,从表头 head开始,逐项向后(next方向)移动 pos ,直至又回到 head (prefetch() 可以不考虑,用于预取以提高遍历速度)。注意:此宏必要把list_head放在数据结构第一项成员,至此,它的地址也就是结构变量的地址。
2.使用方法(以访问当前进程的子进程为例):
struct list_head {?struct list_head *next, *prev;};
在struct task_struct 中有如下定义:struct list_head children;
所以
struct task_struct *task;
struct list_head *list;
list_for_each(list,current-chilidren) {
????????????? task = list_entry(list, struct task_struct, sibling);/*task指向当前的某个子进程*/
}
其中用到了函数list_entry():这个函数的作用在图1中表示就是可以通过已知的指向member子项的指针,获得整个结构体的指针(地址)#define list_entry(ptr, type, member) \????????container_of(ptr, type, member) 二、list_for_each_entry:在Linux内核源码中,经常要对链表进行操作,其中一个很重要的宏是list_for_each_entry:意思大体如下:假设只有两个结点,则第一个member代表head,list_for_each_entry的作用就是循环遍历每一个pos中的member子项。图1:pos:? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???pos:___________? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? ____________|? ?? ?? ?? ?? ?? ?? ???|? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? |? ?? ?? ?? ?? ?? ?? ?? ???||? ?? ?? ?? ?? ?? ?? ???|? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? |? ?? ?? ?? ?? ?? ?? ?? ???||? ? ...........? ???? ?|? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? |? ?................? ???? ||? ?? ?? ?? ?? ?? ?? ???|? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? |? ?? ?? ?? ?? ?? ?? ?? ?? ?||? ?? ?? ?? ?? ?? ?? ???|? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? |? ?? ?? ?? ?? ?? ?? ?? ?? ?||? ?? member:? ? |? ?? ?? ?? ?? ??? ?_________|__ member? ? ||? ?{? ?? ?? ?? ?? ?? ?|? ?? ?? ?? ?? ? |? ?? ?? ?? ?? ?? ?? ?|??{? ?? ?? ?? ?? ?? ?? ???||? ?? ?? ?*prev;?? ?|? ?? ?? ?? ?? ? |? ?? ?? ?? ?? ?? ??? |? ?? ? *prev;? ?? ???||? ?? ??? *next;??????? --|----------? ?? ?? ?? ?? ?? ???|? ?? ???*next;-------------|? ? }????????????????|? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???|??}? ?? ?? ?? ?? ?? ?? ? |? ?? ??
您可能关注的文档
- 第八章 ControlCenter4 使用指南.pptx
- 第八章 ControlLogix5000培训.pptx
- 第八章 CooCox-ARM_Cortex_MCU_Development_Tools_V02_CN.pdf
- LCD的原理及驱动方法简介及应用.pdf
- 第八章 Cool Edit Pro 加速使用方法.ppt
- 抗J亚群禽白血病病毒囊膜糖蛋白特异性单克隆抗体的研制与其特性.pdf
- 拷贝数变异与其研究进展.pdf
- lc温度测量模块的种类和功能规格as pdf.pdf
- 柯达智能磨皮滤镜简介与安装方法(图文).docx
- 第八章 Cool+Edit+Pro+图文教程.pdf
- 广东省广州省实验中学教育集团2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州大学附属中学2025-2026学年八年级上学期奥班期中物理试题(解析版).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(含答案).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(解析版).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 2026《中国人寿上海分公司营销员培训体系优化研究》18000字.docx
- 《生物探究性实验教学》中小学教师资格模拟试题.docx
原创力文档

文档评论(0)