Linux Kernel linked list (list. h)

Source: Internet
Author: User
Linux Kernel linked list (list. h)-Linux general technology-Linux programming and kernel information. The following is a detailed description. (1) Declare list.

By default, it is declared that the next and prev of the linked list point to itself. You can use the following macros.

1. # define LIST_HEAD_INIT (name) {& (name), & (name )}

2. # define LIST_HEAD (name )\

Struct list_head name = LIST_HEAD_INIT (name)

3. static inline void INIT_LIST_HEAD (struct list_head * list)

{
List-> next = list;
List-> prev = list;
}

(2) Add a list to the linked list and put it behind the head.

Static inline void list_add (struct list_head * new, struct list_head * head)
{
_ List_add (new, head, head-> next );
}
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;
Prev-> next = new;
}

(3) Add a list to the Linked list (tail), that is, put it in front of the head.

Static inline void list_add_tail (struct list_head * new, struct list_head * head)
{
_ List_add (new, head-> prev, head );
}

Through this line, we can find that the linked list is very convenient and flexible. Head-> prev is the tail of the linked list (Circular linked list.

(4) Delete the linked list node (list)

Static inline void list_del (struct list_head * entry)
{
_ List_del (entry-> prev, entry-> next );
Entry-> next = list_python1;
Entry-> prev = list_python2;
}
Static inline void _ list_del (struct list_head * prev, struct list_head * next)
{
Next-> prev = prev;
Prev-> next = next;
}

(5) judge whether the list is empty

Static inline int list_empty (const struct list_head * head)
{
Return head-> next = head;
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.