Linux驱动开发10——内核环形双向链表

Linux内核环形双向链表本身不实现锁机制,需要驱动本身完成锁机制实现。

1.1、list_head结构体

#include <linux/list.h>

struct list_head {
struct list_head *next;
struct list_head *prev;
}; list_head结构体本身只包含next和prev两个节点,实际使用时需要自定义结构体包含list_head结构体,如: struct user_struct
{
struct list_head list;
int flags; /* user own data */
};

1.2、初始化

INIT_LIST_HEAD(struct list_head *list_head);
或者
LIST_HEAD(struct list_head list_head);

1.3、操作函数

#include <linux/list.h>

在链表头添加链表节点
list_add(struct list_head *new, struct list_head *head); 在链表尾添加链表节点
list_add_tail(struct list_head *new, struct list_head *head); 删除链表节点
list_del(struct list_head *entry);
list_del_init(struct list_head *entry); 移动链表节点
list_move(struct list_head *entry, struct list_head *head);
list_move_tail(struct list_head *entry, struct list_head *head); 检查链表是否为空,如果为空,返回非零值
list_empty(list_move(struct list_head *head); 遍历链表
list_for_each(struct list_head *cursor, struct list_head *list);
上一篇:QA,敢问路在何方?听听微软资深QA怎么说~


下一篇:ABP入门系列(20)——使用后台作业和工作者