Chinaunix首页 | 论坛 | 博客
  • 博客访问: 36972
  • 博文数量: 9
  • 博客积分: 246
  • 博客等级: 二等列兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-07 20:46
文章分类

全部博文(9)

文章存档

2011年(7)

2008年(2)

我的朋友

分类: LINUX

2011-03-27 11:33:15

  1. /**
  2. * list_for_each_entry  -       iterate over list of given type
  3. * @pos:        the type * to use as a loop cursor.
  4. * @head:       the head for your list.
  5. * @member:     the name of the list_struct within the struct.
  6. */
  7. #define list_for_each_entry(pos, head, member)                          \
  8.         for (pos = list_entry((head)->next, typeof(*pos), member);      \
  9.              prefetch(pos->member.next), &pos->member != (head);        \
  10.              pos = list_entry(pos->member.next, typeof(*pos), member))
  11. /**
  12. * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  13. * @pos:        the type * to use as a loop cursor.
  14. * @n:          another type * to use as temporary storage
  15. * @head:       the head for your list.
  16. * @member:     the name of the list_struct within the struct.
  17. */

  18. #define list_for_each_entry_safe(pos, n, head, member)                  \
  19.         for (pos = list_entry((head)->next, typeof(*pos), member),      \
  20.                 n = list_entry(pos->member.next, typeof(*pos), member); \
  21.              &pos->member != (head);                                    \
  22.              pos = n, n = list_entry(n->member.next, typeof(*n), member))

以前还不知道这两个函数的区别,主要区别是safe函数可以实现边遍历边删除的操作,而每一个函数只是普通遍历。

但并不是说这个遍历就真的safe了,该同步的还是要同步。

阅读(4078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~