list_head structure

来源:互联网 发布:iphone看图软件 编辑:程序博客网 时间:2024/06/05 03:28
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; seeFigure 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.