首页 > 系统相关 >linux内核数据结构 --- list_head

linux内核数据结构 --- list_head

时间:2023-04-02 20:34:10浏览次数:41  
标签:head struct list --- prev kobject

以 struct kobject 为例,讲解如何使用链表 struct list_head

struct kobject {
    const char        *name;
    struct list_head    entry;
    struct kobject        *parent;
...
};
struct list_head类型变量作为 struct kobject 的成员(从面向对象的角度,也可以看成 struct list_head是某结构体的父类)
struct list_head {
    struct list_head *next, *prev;
};

初始化 struct list_head,其next和prev都指向自己

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

head--->head

向链表尾添加条目

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

添加条目A后,head--->A--->head,添加条目B后,head--->A--->B--->head

遍历链表,取出 struct kobject 实例到 k,

        list_for_each_entry(k, &list, entry)
            xxx;

 

   

标签:head,struct,list,---,prev,kobject
From: https://www.cnblogs.com/god-of-death/p/17281285.html

相关文章

  • SpringBoot集成Activiti7-单独配置数据源
    框架:SpringBoot+Mybatis+Activiti7思路:单独给mybatis和activiti配置datasourceMybati配置单数据源方法单数据源只需要在yml中配置url:jdbc:mysql://localhost:3306/localtest?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatemen......
  • nginx keepalive_timeout 300; 504 Gateway Time-out
    实践:1、http{includemime.types;#includeluawaf.conf;includeproxy.conf;default_typeapplication/octet-stream;server_names_hash_bucket_size512;client_header_buffer_size32k;large_client_header_buffers432k;client_max_b......
  • 力扣---剑指 Offer 34. 二叉树中和为某一值的路径
    给你二叉树的根节点root和一个整数目标和targetSum,找出所有从根节点到叶子节点路径总和等于给定目标和的路径。叶子节点是指没有子节点的节点。 示例1:  输入:root=[5,4,8,11,null,13,4,7,2,null,null,5,1],targetSum=22输出:[[5,4,11,2],[5,8,4,5]]示例2:......
  • odoo 开发入门教程系列-准备一些操作(Action)?
    准备一些操作(Action)?到目前为止,我们主要通过声明字段和视图来构建模块。在任何真实的业务场景中,我们都希望将一些业务逻辑链接到操作按钮。在我们的房地产示例中,我们希望能够:取消或将房产设置为已售出接受或拒绝报价有人可能会说,我们已经可以通过手动更改状态来完成这些事......
  • 实验一-密码引擎-3-加密API研究
    任务详情密码引擎API的主要标准和规范包括:1微软的CryptoAPI2RAS公司的PKCS#11标准3中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出调用不同接口的代码,提交博客......
  • 牛客SQL-非技术快速入门
    01基础查询SQL1查询所有列select*fromuser_profileSQL2查询多列selectdevice_id,gender,age,universityfromuser_profileSQL3查询结果去重selectdistinct(university)fromuser_profileSQL4查询结果限制返回行数top不适用于所有的数据库语言。SQLSERVER......
  • 【Python】Flask-SQLAlchemy PyCharm无法自动补全解决方案
    ✨Flask-Sqlalchemy无法自动补全解决方案PyCharm版本:PyCharm2021.3.3(ProfessionalEdition)flask版本:2.2.3flask-sqlalchemy版本:3.0.3SQLAlchemy版本:2.0.4在使用flask-sqlalchemy中db.Column,primary_key等无法自动补全降低flask-sqlalchemy版本即可解决pipinstallf......
  • 力扣---面试题13. 机器人的运动范围
    地上有一个m行n列的方格,从坐标[0,0]到坐标[m-1,n-1]。一个机器人从坐标[0,0]的格子开始移动,它每次可以向左、右、上、下移动一格(不能移动到方格外),也不能进入行坐标和列坐标的数位之和大于k的格子。例如,当k为18时,机器人能够进入方格[35,37],因为3+5+3+7=18。但它不能进入......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)- Make It Permutation
    题目链接:Problem-C-Codeforces  #include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;#defineendl"\n"intmain(){ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);intT=1;cin>>T;while(......
  • 利民(Thermalright)HR-10 2280 固态硬盘SSD散热器 - 我的硬件配置
    ......