Linux内核驱动学习(六)

1、INIT_LIST_HEAD:创建/初始化链表—在Linux内核中查找其原型

static inline void INIT_LIST_HEAD(struct list_head *list){ list->next = list; list->prev = list;}

使list_head链表的前驱和后继都指向其自身。进而初始化

2、list_add:在链表头插入节点。

/** * list_add – add a new entry //增加新节点 * @new: new entry to be added //参数new:将要被增加的节点入口 * @head: list head to add it after //参数head:增加节点在链表list_head的的表头的后面。 * Insert a new entry after the specified head. * This is good for implementing stacks.—》可用于实现栈 */static inline void list_add(struct list_head *new, struct list_head *head){ __list_add(new, head, head->next);// 在head与head->next之间插入新节点}

追踪__list_add(new, head, head->next);

static inline void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next) { next->prev = new; new->next = next; new->prev = prev; prev->next = new;}

3、list_add_tail :链表尾插入节点

/** * list_add_tail – add a new entry //增加新节点 * @new: new entry to be added //新增加的节点 * @head: list head to add it before //增加节点在head之前 * * Insert a new entry before the specified head. * This is useful for implementing queues. //可用于实现队列 */static inline void list_add_tail(struct list_head *new, struct list_head *head){ __list_add(new, head->prev, head); //在head之前与head->prev之间插入节点,即在链表队尾插入}

4、list_del:删除节点

static inline void list_del(struct list_head *entry){ __list_del(entry->prev, entry->next); entry->next = LIST_POISON1; entry->prev = LIST_POISON2;}

list_del()函数将删除后的prev\next指针分别设为LIST_POISON1、LIST_POISON2

两个特殊值,是为了保证不在链表中的节点项不可访问,对以上两值的访问将引起页面故障

5、list_entry:取出节点,返回指向包含指针域的外部结构的指针

/** * list_entry – get the struct for this entry —>返回指向节点的结构的指针(包含head_list的外部结构) * @ptr:the &struct list_head pointer. —>pos * @type:the type of the struct this is embedded in. —>嵌入对象的结构类型 * @member:the name of the list_struct within the struct. —>嵌入对象的结构中的指针域list_head结构的名字 */#define list_entry(ptr, type, member) \ container_of(ptr, type, member)

6、liast_for_each:遍历链表—利用source insight 查找其相关用法

,我提着行李,独自一人向远方走去,夕阳将我的身影拉得斜长,

Linux内核驱动学习(六)

相关文章:

你感兴趣的文章:

标签云: