zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    MVC3.0与C#截取字符串
    MVC3.0图片滚动和相册展示(上)
    MVC3.0视频点播及上传格式转化
    职位VS能力
    liblfds 测试
    dpdk 相关概念
    WAR文件
    在word中选择一个矩形区域
    IP地址 网段的划分
    ipconfig...ping...netstat
  • 原文地址:https://www.cnblogs.com/justin-y-lin/p/10694516.html
Copyright © 2011-2022 走看看