将new所代表的list_head插入head所索引的队列的尾部
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}
将new所代表的list_head插入到next索引的双链表(next索引双链表的第一个节点)的尾部
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
{
next->prev = new; //(1)
new->next = next; //(2)
new->prev = prev; //(3)
prev->next = new; //(4)
}
next
new head----+----------------------------------------------+
| | |
| list_head | list_head list_head list_head |
| |---------| | |---------| |---------| |---------| |
+-->| *next | +--->| *next |-->| *next |-->| *next |---+
|---------| |---------| |---------| |---------|
| *prev | +--| *prev |<--| *prev |<--| *prev |<--+---prev
|---------| | |---------| |---------| |---------| |
| |
+--------------------------------------------+
+---------------------+
| next | (4)
new| head----+ +-----------------------------------------+
| | | |
+--+ list_head | list_head list_head list_head |
| |---------|(2) | |---------| |---------| |---------| |
+-->| *next |-----+--->| *next |-->| *next |-->| *next |---+
|---------| |---------| |---------| |---------|
+---| *prev |<---------| *prev |<--| *prev |<--| *prev |<--+---prev
| |---------| (1) |---------| |---------| |---------| |
| |
+------------------------------------------------------------------+
(3)
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}将new所代表的list_head插入到next索引的双链表(next索引双链表的第一个节点)的尾部
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
{
next->prev = new; //(1)
new->next = next; //(2)
new->prev = prev; //(3)
prev->next = new; //(4)
}next
new head----+----------------------------------------------+
| | |
| list_head | list_head list_head list_head |
| |---------| | |---------| |---------| |---------| |
+-->| *next | +--->| *next |-->| *next |-->| *next |---+
|---------| |---------| |---------| |---------|
| *prev | +--| *prev |<--| *prev |<--| *prev |<--+---prev
|---------| | |---------| |---------| |---------| |
| |
+--------------------------------------------+
+---------------------+
| next | (4)
new| head----+ +-----------------------------------------+
| | | |
+--+ list_head | list_head list_head list_head |
| |---------|(2) | |---------| |---------| |---------| |
+-->| *next |-----+--->| *next |-->| *next |-->| *next |---+
|---------| |---------| |---------| |---------|
+---| *prev |<---------| *prev |<--| *prev |<--| *prev |<--+---prev
| |---------| (1) |---------| |---------| |---------| |
| |
+------------------------------------------------------------------+
(3)
本文详细介绍了Linux内核中的`list_add_tail()`函数,该函数用于将新的`list_head`结构体插入到指定链表的尾部。通过`__list_add()`函数实现,更新了新节点及前后节点的指针关系,确保链表的正确连接。

271

被折叠的 条评论
为什么被折叠?



