内核双向链表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) );})
本文解析了内核双向链表list.h中的list_entry定义及其作用。通过详细解释container_of宏的工作原理,帮助读者理解如何从一个指向list_head结构的指针中获取其所属结构体。
287

被折叠的 条评论
为什么被折叠?



