Analysis of commonly used list in Linux (6)

Source: Internet
Author: User
Tags prefetch
Describes the iterate over functions of a list:
1. # define list_for_each (Pos, head )/
For (Pos = (head)-> next; prefetch (POS-> next), pos! = (Head );/
Pos = pos-> next)
There seems to be nothing to say about this traversal loop. Starting from head-> next, we use the next pointer to traverse the loop. prefetch pushes the pointer into the CPU L1 cache.

# DEFINE _ list_for_each (Pos, head )/
For (Pos = (head)-> next; pos! = (Head); Pos = pos-> next)
The prefetch operation is missing.

# Define list_for_each_prev (Pos, head )/
For (Pos = (head)-> Prev; prefetch (POS-> PREV), pos! = (Head );/
Pos = pos-> PREV)
This is an operation with prefetch that is traversed using the prev pointer.

# Define list_for_each_safe (Pos, N, head )/
For (Pos = (head)-> next, n = pos-> next; pos! = (Head );/
Pos = n, n = pos-> next)
Safe iterate over function. parameter n is a linked list for temporary storage.

2. # define list_for_each_entry (Pos, Head, member )/
For (Pos = list_entry (head)-> next, typeof (* POS), member );/
Prefetch (POS-> member. Next), & Pos-> member! = (Head );/
Pos = list_entry (POS-> member. Next, typeof (* POS), member ))
This function uses the well-known list_entry that has been explained previously, namely the container_of function.
POS is a type-structured pointer, head is the list header node, and member is a member of struct.
We can see that this function uses the next pointer to traverse member members.

# Define list_for_each_entry_reverse (Pos, Head, member )/
For (Pos = list_entry (head)-> Prev, typeof (* POS), member );/
Prefetch (POS-> member. Prev), & Pos-> member! = (Head);/# define list_for_each_entry_from (Pos, Head, member )/
For (; prefetch (POS-> member. Next), & Pos-> member! = (Head );/
Pos = list_entry (POS-> member. Next, typeof (* POS), member ))
Pos = list_entry (POS-> member. Prev, typeof (* POS), member ))
Same as above, it uses the prev pointer to traverse member members.

# Define list_prepare_entry (Pos, Head, member )/
(POS )? : List_entry (Head, typeof (* POS), member ))
Obtain the POs pointer for list_for_each_entry_continuer (). If the POS is empty, obtain the Member member entry address of the head node.

# Define list_for_each_entry_continue (Pos, Head, member )/
For (Pos = list_entry (POS-> member. Next, typeof (* POS), member );/
Prefetch (POS-> member. Next), & Pos-> member! = (Head );/
Pos = list_entry (POS-> member. Next, typeof (* POS), member ))
Use the next pointer to traverse member members starting from POS.

# Define list_for_each_entry_from (Pos, Head, member )/
For (; prefetch (POS-> member. Next), & Pos-> member! = (Head );/
Pos = list_entry (POS-> member. Next, typeof (* POS), member ))
Use the next pointer to traverse the members starting from the current position.

3. The Safe series and RCU system functions are similar to the above and are no longer repeated.
 

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.