linux雙向鏈表List結構分析

雙向鏈表是linux內核中的一個核心數據結構,由於其運用場景衆多如task列表、設備列表等等,因此內核將其操作邏輯獨立了出來。下面我們以i2c的設備樹列表爲例來看一下List列表的使用方法。

如圖所示,雙向鏈表不包含任何數據,在使用時,將其嵌入到目標結構體中使用。且第一個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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章