ChinaUnix.net
相关文章推荐:

list_for_each_entry

当使用 list_for_each_entry 对一个 list 进行遍历时, 如果这个list可能为空,在使用这个宏之前,是不是必须得加 list_empty 的判断? 而用传统的方式 for (entry = list->next; entry != NULL; entry = entry->next) {} 如果list为空,就自动跳出去了,前面就不用判断是否为空了

by davhuang - 内核源码 - 2007-10-22 19:28:51 阅读(14639) 回复(8)

相关讨论

大家都知道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)

by smalloc - 内核源码 - 2012-11-12 14:39:41 阅读(2516) 回复(2)

本帖最后由 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,...

by jiufei19 - 内核源码 - 2014-04-23 19:18:58 阅读(4960) 回复(21)

下面是两个宏,搞不明白为什么第二个是“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...

by amarant - 内核源码 - 2011-03-25 19:39:50 阅读(12787) 回复(7)

在Linux内核源码中,经常要对链表进行操作,其中一个很重要的宏是list_for_each_entry: 意思大体如下: 假设只有两个结点,则第一个member代表head, list_for_each_entry的作用就是循环遍历每一个pos中的member子项。 图1: pos: pos: ___________ ____________ | | ...

by thelordsaves - 内核源码 - 2012-06-14 15:46:08 阅读(23604) 回复(2)

如下问题及答案, 但我无法理解 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!) 答...

by zylthinking - 内核源码 - 2013-04-08 13:15:01 阅读(3763) 回复(5)

#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 <-----挂了

by uauaky - 内核源码 - 2012-11-05 21:04:07 阅读(1343) 回复(3)

本帖最后由 十年梦生 于 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)来依次遍历访...

by 十年梦生 - 内核源码 - 2010-03-25 18:19:17 阅读(5212) 回复(1)

先祝大家新春快乐!牛年大吉大利!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)?而非要写这么一个遍历...

by gaowg2000 - 内核源码 - 2009-01-27 14:52:44 阅读(6830) 回复(5)

找了很多没发现有问题,这点是唯一可怀疑的。。。 请大家指教

by epegasus - 内核源码 - 2012-02-05 09:08:52 阅读(5384) 回复(8)

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 — 返回数组中当前的键/值对并将数组指针向前...

by xmlamp - php文档中心 - 2010-01-19 13:41:23 阅读(1866) 回复(0)