Summary of inserting the Add function in "list. H" in Linux kernel learning

Source: Internet
Author: User

The first statement and initialization are not described in detail here. Please refer to my previous blog post the corresponding code here:

# Ifndef _ linux_list_h # DEFINE _ linux_list_h # define offsetof1 (type, member) (size_t) & (type *) 0)-> member) # define container_of (PTR, type, member) ({\ const typeof (type *) 0)-> member) * _ mptr = (PTR); \ (type *) (char *) _ mptr-offsetof1 (type, member) ;}) static inline void prefetch (const void * X) {;} static inline void prefetchw (const void * X ){;} // # define list_poison1 (void *) 0x00100100) // # define list_policon2 (void *) 0x00200200) # define list_poison1 0 # define list_poison2 0 struct list_head {struct list_head * Next, * Prev; // bidirectional linked list}; # define list_head_init (name) {& (name ), & (name)} // initialize next and Prev with the same object. # define list_head (name) \ struct list_head name = list_head_init (name) # define init_list_head (PTR) do {\ // initialization means to point the pointer to itself (PTR) -> next = (PTR); (PTR)-> Prev = (PTR); \} while (0)

 

The following is a detailed analysis of the insert function. In fact, the insert function is very simple and can be understood as long as you have learned the C language. Here is a simple explanation:

/** Insert a new entry between two known consecutive entries. ** this is only for internal list manipulation where we know * The Prev/next entries already! */Static inline void _ list_add (struct list_head * new1, // Insert a new entry, insert it in the middle of Prev and next struct list_head * Prev, // struct list_head * Next) {next-> Prev = new1; new1-> next = next; new1-> Prev = Prev; Prev-> next = new1 ;} /*** list_add-Add a new entry * @ New: New entry to be added * @ head: List head to add it after ** Insert a new entry after the specified head. * This is good for implementing stacks. */static inline void list_add (struct list_head * new1, struct list_head * head) // the header insertion method. Call _ list_add () to implement {_ list_add (new1, Head, head-> next);}/*** list_add_tail-Add a new entry * @ New: New entry to be added * @ head: list head to add it before ** Insert a new entry before the specified head. * This is useful for implementing queues. */static inline void list_add_tail (struct list_head * new1, struct list_head * head) // end interpolation {_ list_add (new1, head-> Prev, head );}

 

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.