list_head structure

3.2.2.3. Doubly linked lists

A new list is created by using the LIST_HEAD(list_name) macro. It declares a new variable named list_name of type list_head, which is a dummy first element that acts as a placeholder for the head of the new list, and initializes the prev and next fields of the list_head data structure so as to point to the list_name variable itself; see Figure 3-3 (b).

Table 3-1. List handling functions and macros

Name

Description

list_add(n,p)

Inserts an element pointed to by n right after the specified element pointed to by p. (To insert n at the beginning of the list, set p to the address of the list head.)

list_add_tail(n,p)

Inserts an element pointed to by n right before the specified element pointed to by p. (To insert n at the end of the list, set p to the address of the list head.)

list_del(p)

Deletes an element pointed to by p. (There is no need to specify the head of the list.)

list_empty(p)

Checks if the list specified by the address p of its head is empty.

list_entry(p,t,m)

Returns the address of the data structure of type t in which the list_head field that has the name m and the address p is included.

list_for_each(p,h)

Scans the elements of the list specified by the address h of the head; in each iteration, a pointer to the list_head structure of the list element is returned in p.

list_for_each_entry(p,h,m)

Similar to list_for_each, but returns the address of the data structure embedding the list_head structure rather than the address of the list_head structure itself.



你可能感兴趣的:(list,insert,each,structure)