内核双向链表list.h中的list_entry

来源:互联网 发布:mac如何查看运行程序 编辑:程序博客网 时间:2024/04/29 19:25

内核双向链表list.h中的list_entry定义:

#define list_entry(ptr, type, member)      container_of(ptr, type, member)

程序注释为:

/**
 * list_entry - get the struct for this entry
 * @ptr:    the &struct list_head pointer.
 * @type:    the type of the struct this is embedded in.
 * @member:    the name of the list_struct within the struct.
 */

刚开始没有理解。

现在明白,注释的意思是从一个实体中得到它的结构体。
#define container_of(ptr, type, member) ({const typeof( ((type *)0)->member ) *__mptr = (ptr); (type *)( (char *)__mptr - offsetof(type,member) );})