list_head 是kernel中相當重要的一個data structure,它是一個double linked list。
定義在 linux/list.h,原型如下
struct list_head
{
struct list_head *next, *prev;
};
同一個.h檔有其相關的macro
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
透過這兩個macro可以將list_head初始化,通常我們會這樣用
LIST_HEAD(test) /* 將test初始化 */
這個macro等同
struct list_head test = {&test, &test}; /* 將test的next與prev指向test本身 */
同一個.h檔中定義一些對這個list操作的inline函數
static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->next = list;
list->prev = list;
}
以下的部份待補
全站熱搜
留言列表