我是靠谱客的博主 害羞画板,这篇文章主要介绍linux kernel链表相关结构及操作LIST_HEADlist_add_taillist_for_each_entry,现在分享给大家,希望可以做个参考。

相关内容都定义在 include/linux/list.h文件中

LIST_HEAD

复制代码
1
2
3
4
5
#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name) #define LIST_HEAD_INIT(name) { &(name), &(name) }

list_add_tail

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
static inline void list_add_tail(struct list_head *new, struct list_head *head) { __list_add(new, head->prev, head); } static inline void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next) { next->prev = new; new->next = next; new->prev = prev; WRITE_ONCE(prev->next, new); }

list_for_each_entry

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/** * 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_head within the struct. */ #define list_for_each_entry(pos, head, member) for (pos = list_first_entry(head, typeof(*pos), member); &pos->member != (head); pos = list_next_entry(pos, member)) /** * list_first_entry - get the first element from a list * @ptr: the list head to take the element from. * @type: the type of the struct this is embedded in. * @member: the name of the list_head within the struct. * * Note, that list is expected to be not empty. */ #define list_first_entry(ptr, type, member) list_entry((ptr)->next, type, member) /** * list_entry - 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_head within the struct. */ #define list_entry(ptr, type, member) container_of(ptr, type, member) /** * list_next_entry - get the next element in list * @pos: the type * to cursor * @member: the name of the list_head within the struct. */ #define list_next_entry(pos, member) list_entry((pos)->member.next, typeof(*(pos)), member)

最后

以上就是害羞画板最近收集整理的关于linux kernel链表相关结构及操作LIST_HEADlist_add_taillist_for_each_entry的全部内容,更多相关linux内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部