linux内核数据结构 — list_head()-LINUX
linux内核数据结构 — list_head()
struct kobject {
const char *name;
struct list_head entry;
struct kobject *parent;
...
};
struct list_head {
struct list_head *next, *prev;
};
初始化 struct list_head,其next和prev都指向自己
static inline void INIT_LIST_HEAD(struct list_head *list)
{
WRITE_ONCE(list->next, list);
WRITE_ONCE(list->prev, list);
}
head—>head
向链表尾添加条目
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}
添加条目A后,head—>A—>head,添加条目B后,head—>A—>B—>head
遍历链表,取出 struct kobject 实例到 k,
list_for_each_entry(k, &list, entry)
xxx;
————————
struct kobject {
const char *name;
struct list_head entry;
struct kobject *parent;
...
};
struct list_head {
struct list_head *next, *prev;
};
初始化 struct list_head,其next和prev都指向自己
static inline void INIT_LIST_HEAD(struct list_head *list)
{
WRITE_ONCE(list->next, list);
WRITE_ONCE(list->prev, list);
}
head—>head
向链表尾添加条目
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}
添加条目A后,head—>A—>head,添加条目B后,head—>A—>B—>head
遍历链表,取出 struct kobject 实例到 k,
list_for_each_entry(k, &list, entry)
xxx;