大家都知道list_for_each_entry_safe中才可以调用list-del() 但是在list_for_each_entry中调用会发生什么呢? static inline void list_del(struct list_head *entry) { __list_del(entry->prev, entry->next); entry->next = list_POISON1; entry->prev = list_POISON2; } #define list_POISON1 ((void *) 0x00100100) #define list_POISON2 ((void *) 0x00200200)
本帖最后由 jiufei19 于 2014-04-22 20:59 编辑 正在仔细学习RCU的机制,对下面这个宏有点不明白,请各位指点下,谢谢! 645 #define list_for_each_entry_rcu(pos, head, member) \ 646 for (pos = list_entry((head)->next, typeof(*pos), member); \ 647 prefetch(rcu_dereference(pos)->member.next), \ 648 &pos->member != (head); \ 649 pos = list_entry(pos->member.next,...
下面是两个宏,搞不明白为什么第二个是“safe“的 :dizzy:[code]/** * list_for_each_entry - iterate over list of given type * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_struct within the struct. */ #define list_for_each_entry(pos, head, member) \ for (pos = list_entry((head)->n...
在Linux内核源码中,经常要对链表进行操作,其中一个很重要的宏是list_for_each_entry: 意思大体如下: 假设只有两个结点,则第一个member代表head, list_for_each_entry的作用就是循环遍历每一个pos中的member子项。 图1: pos: pos: ___________ ____________ | | ...
如下问题及答案, 但我无法理解 Quick Quiz 3: Why do we need to pass two pointers into hlist_for_each_entry_rcu() when only one is needed for list_for_each_entry_rcu()? Answer: Because in an hlist it is necessary to check for NULL rather than for encountering the head. (Try coding up a single-pointer hlist_for_each_entry_rcu(). If you come up with a nice solution, it would be a very good thing!) 答...
#define list_for_each_safe(pos, n, head) \ for (pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next) 如果这里我在访问pos的时候,n被释放掉了,这样不是会panic。。。不解 pos = (head)->next, n = pos->next; 访问pos节点 释放n pos = n, n = pos->next <-----挂了
本帖最后由 十年梦生 于 2010-03-24 17:27 编辑 :mrgreen: :mrgreen:list_for_each遍历子进程方法,顺便分析下container_of宏的实现过程 Linux系统中的每个进程都有一个父进程(init进程除外);每个进程还有0个或多个子进程。在进程描述符中parent指针指向其父进程,还有一个名为children的子进程链表(父进程task_struct中的children相当于链表的表头)。 而我们可以使用list_for_each(/include/linux/list.h)来依次遍历访...
先祝大家新春快乐!牛年大吉大利!happy 牛 year! 最近刚开始看linux内核。没有搞懂list_for_each()函数。 函数原型如下: #define list_for_each(pos, head) \ for (pos = (head)->next; prefetch(pos->next), pos != (head); \ pos = pos->next) 我个人的理解:该函数是对链表的遍历,遍历结束后pos = head。 请问,为什么不直接将head的值赋值给pos呢(如:pos = head)?而非要写这么一个遍历...
100,'Oil'=>10,'Spark Plugs'=>4); foreach ($prices as $key=>$value) echo $key.'=>'.$value.' '; ?> 最终打印出: Tires=>100 Oil=>10 Spark Plugs=>4 100,'Oil'=>10,'Spark Plugs'=>4); while($element = each($prices)) { echo $element['key']; echo '-'; echo $element['value']; echo ' '; } ?> 最终打印出: Tires-100 Oil-10 Spark Plugs-4 each — 返回数组中当前的键/值对并将数组指针向前...