如圖所示,雙向鏈表不包含任何數據,在使用時,將其嵌入到目標結構體中使用。且第一個list_head不與數據機構體關聯,作爲整個鏈表的起始。
List的實現代碼在kernel\include\linux\list.h中,部分常用函數、宏如下:
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->next = list;
list->prev = list;
}
/**
* 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 list_en