我是靠谱客的博主 无奈白开水,这篇文章主要介绍list_for_each_entry详解,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<span style="font-size:18px;">先上相关代码:</span> <pre name="code" class="cpp">/** * list_for_each_entry_rcu - iterate over rcu 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. * * This list-traversal primitive may safely run concurrently with * the _rcu list-mutation primitives such as list_add_rcu() * as long as the traversal is guarded by rcu_read_lock(). */ #define list_for_each_entry_rcu(pos, head, member) for (pos = list_entry_rcu((head)->next, typeof(*pos), member); prefetch(pos->member.next), &pos->member != (head); pos = list_entry_rcu(pos->member.next, typeof(*pos), member))


复制代码
1

复制代码
1
复制代码
1

上面用到了list_entry_rcu(),上代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
/** * list_entry_rcu - get the struct for this entry * @ptr: the &struct list_head pointer. * @type: the type of the struct this is embedded in. * @member: the name of the list_struct within the struct. * * This primitive may safely run concurrently with the _rcu list-mutation * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). */ #define list_entry_rcu(ptr, type, member) container_of(rcu_dereference(ptr), type, member)


list_entry_rcu作用:根据指向结构体type中成员member的指针ptr,返回指向该结构体的指针。prefetch(pos->member.next):通知CPU将()内的数据预取,以提高效率。判断条件:&pos->member != (head)list_for_each_entry_rcu的作用:head为链表的头,它作为一个成员member被包含在pos指向的结构体中,从head开始遍历链表,直到pos又指向包含head的结构体,停止遍历。


最后

以上就是无奈白开水最近收集整理的关于list_for_each_entry详解的全部内容,更多相关list_for_each_entry详解内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部