linux内核计算list的长度,Linux内核通用链表 linux/list.h阅读

#ifndef _LINUX_LIST_H

#define _LINUX_LIST_H   //宏定义,不做过多解释,就是检查是否包含了linux/list.h

#ifdef __KERNEL__

#include

#include

#include

/*

* These are non-NULL pointers that will result in page faults

* under normal circumstances, used to verify that nobody uses

* non-initialized list entries.

*/

这些非空的指针会导致页错误,在正常环境下,用来验证无人使用为初始化的链表节点,入口.也有解释说能引起中断,或者关于这个地址的处理内核处理的很简单,要么打印日志信息报错,要么直接不处理.

#define LIST_POISON1 ((void *) 0x00100100)

#define LIST_POISON2 ((void *) 0x00200200)

/*

* Simple doubly linked list implementation.

*

* Some of the internal functions ("__xxx") are useful when

* manipulating whole lists rather than single entries, as

* sometimes we already know the next/prev entries and we can

* generate better code by using them directly rather than

* using the generic single-entry routines.

*/

entry似乎应该翻译成表或者节点。

简单的双向链表实现:一些内部函数在熟练操作整个链表比单个入口更有用,当我们已经知道next/prev入口,通过使用直接它们比使用一般的单入口程序产生更好的代码。

struct list_head {

struct list_head *next, *prev;

};

#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \

struct list_head name = LIST_HEAD_INIT(name)

如果一开始没有看懂LIST_HEAD_INIT宏定义的话,上面这个应该可以让人豁然开朗,初始化一个name链表,让头和尾都指向自己。

#define INIT_LIST_HEAD(ptr) do { \

(ptr)->next = (ptr); (ptr)->prev = (ptr); \

} while (0)

/*

* Insert a new entry between two known consecutive entries.

*

* This is only for internal list manipulation where we know

* the prev/next entries already!

*/

在已知的连续节点中间插入一个新的节点

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;

}

/**

* list_add - add a new entry

* @new: new entry to be added

* @head: list head to add it after

*

* Insert a new entry after the specified head.

* This is good for implementing stacks.

*/

在制订head节点之后插入一个新的节点,这个适用于栈

static inline void list_add(struct list_head *new, struct list_head *head)

{

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

}

/**

* list_add_tail - add a new entry

* @new: new entry to be added

* @head: list head to add it before

*

* 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);

}

/*

* Insert a new entry between two known consecutive entries.

*

* This is only for internal list manipulation where we know

* the prev/next entries already!

*/

此函数仅供内置链表操作,就是只用于此头文件中所有的关于链表操作的函数就是要已知 prev/next 节点

static inline void __list_add_rcu(struct list_head * new,

struct list_head * prev, struct list_head * next)

{

new->next = next;

new->prev = prev;

smp_wmb();

next->prev = new;

prev->next = new;

}

/**

* list_add_rcu - add a new entry to rcu-protected list

* @new: new entry to be added

* @head: list head to add it after

*

* Insert a new entry after the specified head.

* This is good for implementing stacks.

*

* The caller must take whatever precautions are necessary

* (such as holding appropriate locks) to avoid racing

* with another list-mutation primitive, such as list_add_rcu()

* or list_del_rcu(), running on this same list.

* However, it is perfectly legal to run concurrently with

* the _rcu list-traversal primitives, such as

* list_for_each_entry_rcu().

*/

调用必须提供任何的必要的防范措施(比如固定适当的锁)来避免在运行于同一个链表时和另一个原始的链表操作竞争,比如 list_add_rcu() * or list_del_rcu(), 但是和_rcu 原始的链表遍历同时运行是完全合法的。

static inline void list_add_rcu(struct list_head *new, struct list_head *head)

{

__list_add_rcu(new, head, head->next);

}

/**

* list_add_tail_rcu - add a new entry to rcu-protected list

* @new: new entry to be added

* @head: list head to add it before

*

* Insert a new entry before the specified head.

* This is useful for implementing queues.

*

* The caller must take whatever precautions are necessary

* (such as holding appropriate locks) to avoid racing

* with another list-mutation primitive, such as list_add_tail_rcu()

* or list_del_rcu(), running on this same list.

* However, it is perfectly legal to run concurrently with

* the _rcu list-traversal primitives, such as

* list_for_each_entry_rcu().

*/

static inline void list_add_tail_rcu(struct list_head *new,

struct list_head *head)

{

__list_add_rcu(new, head->prev, head);

}

/*

* Delete a list entry by making the prev/next entries

* point to each other.

*

* This is only for internal list manipulation where we know

* the prev/next entries already!

*/

看不懂此函数可以看下面就明白了,删除已知节点,需要知道节点的后继和前趋

static inline void __list_del(struct list_head * prev, struct list_head * next)

{

next->prev = prev;

prev->next = next;

}

/**

* list_del - deletes entry from list.

* @entry: the element to delete from the list.

* Note: list_empty on entry does not return true after this, the entry is

* in an undefined state.

*/

static inline void list_del(struct list_head *entry)

{

__list_del(entry->prev, entry->next);

entry->next = LIST_POISON1;

entry->prev = LIST_POISON2;

}0b1331709591d260c1c78e86d0c51c18.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/557797.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

分析Spring容器启动流程 Spring初始化

分析Spring容器启动流程 Spring初始化 每当启动Web容器时(例如Tomcat),会读取Web应用中的web.xml文件。以下这段代码就是启动Spring容器的关键代码。 ContextLoaderListener 类继承了ContextLoader,实现 了ServletContextListen…

linux 喂狗时间,狗狗正确喂食时间表,喂狗最佳时间指南

未满3月龄的狗狗,每天的早、晚餐分别在7~8点与19~20点喂食,期间每隔3~4小时再喂一次。未满6月龄的狗狗,7~8点喂早餐,12~13点喂午餐,19~20点喂晚餐…

帮帮忙—ssm框架中,简单自定义标签SimpleTagSupport如何注入spirng中的bean

权限太多,想用简单自定义标签来控制,但遇到一个头疼的问题,不能用autowird自动注入spring管理的bean,让人恼火; 经过周折,终于解决问题,与大家一起分享,可能不是最好的方法&#xf…

linux连接svn上代码,代码管理平台介绍、安装svn、客户端上使用svn(linux)、客户端上使用svn(windows)...

代码管理平台介绍代码管理平台介绍--svn版本控制,记录若干文件内容变化,以便未来查阅特定版本修订状况.好比某一个业务,须要不断更新,好比产品经理这周提交了产品新的需求,改动了一些代码,咱们把新的代码上…

Spring初始化:org.springframework.we...ContextLoaderListener的作用

Spring初始化&#xff1a;org.springframework.web.context.ContextLoaderListener的作用 在web.xml种这样配置 <listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>ContextLoaderList…

Linux统一编程接口,restful接口设计规范总结

一、重要概念&#xff1a;REST,即Representational State Transfer的缩写。我对这个词组的翻译是"表现层状态转化"。Resource(资源) &#xff1a;对象的单个实例。 例如&#xff0c;一只动物。它可以是一段文本、一张图片、一首歌曲、一种服务&#xff0c;总之就是一…

重写hashcode和equals方法

一。前言 我们都知道&#xff0c;要比较两个对象是否相等时需要调用对象的equals()方法&#xff0c;即判断对象引用所指向的对象地址是否相等&#xff0c;对象地址相等时&#xff0c;那么与对象相关的对象句柄、对象头、对象实例数据、对象类型数据等也是完全一致的&#xff0…

js中遇到的一个错误Uncaught SyntaxError: missing )after argument list

报的错误如下&#xff1a; 代码&#xff1a; 解决&#xff1a; 加上引号即可。

c语言第六次实验报告,第一年C语言实验报告6列

成都理工大学计算机工程学院“编程基础”实验报告1. 实验目的(1)精通一维数组. 二维数组的定义&#xff0c;初始化以及输入和输出方法(2)掌握字符数组和字符串函数的使用(3)掌握与数组有关的常用算法2. 实验内容(1)在给定的字符串中找到指定的字符&#xff1b;要求:①通过直接初…

IDEA中maven的Plugins报红解决方法

IDEA中maven的Plugins报红解决方法 Idea中maven的Plugins报红解决方法 我的maven项目中plugins下的所有文件都报红&#xff0c;查看报错&#xff0c;这是Maven中plugins没有存入本地的仓库&#xff0c;点击Settings查看Build&#xff0c;Execution…》》Build Tools》》Maven》…

JavaScript 中的 window onload 应该什么时候写

JavaScript 中的 window onload 应该什么时候写 1. 页内式 JS 代码 1.1 页内式 JS 代码写在 head 内部 如果 script 标签写在 head 标签内部&#xff0c;则位于 body 内的元素将晚于 JS 代码加载&#xff0c;那么其中一些获取 DOM 元素的方法将无法取得元素&#xff08;返回 …

android歌词效果,自定义View:Android歌词控件

TicktockMusic 音乐播放器项目相关文章汇总&#xff1a;简介之前做 TicktockMusic 音乐播放器&#xff0c;一个必要的需求肯定是歌词&#xff0c;在 github 上找了几个&#xff0c;发现或多或少都有点不满足需求&#xff0c;所以就自己动手写了一个&#xff0c;本篇文章主要介绍…

IDEA项目中 target 目录的作用

IDEA项目中 target 目录的作用 target是idea默认的编译路径&#xff0c;用来存放项目的&#xff1a;文件和目录、jar包、war包、class文件等。

bc8android汽车中控屛功能有哪些,丰田酷路泽中控台的8大功能 你们知道都是干什么用的?...

兰德酷路泽(参数|图片)中控台的8大功能 ①&#xff1a;高低速四驱调节高低速四驱调节系统&#xff0c;有着两个方向&#xff0c;L4和H4H4&#xff0c;指的是高速四驱&#xff0c;开启H4的时候适合走沙石路面&#xff0c;泥泞路面&#xff0c;雪地&#xff0c;沙石地等。最高车速…

微服务和分布式的区别

微服务和分布式的区别 1.分布式 将一个大的系统划分为多个业务模块&#xff0c;业务模块分别部署到不同的机器上&#xff0c;各个业务模块之间通过接口进行数据交互。区别分布式的方式是根据不同机器不同业务。 上面&#xff1a;service A、B、C、D 分别是业务组件&#xff…

android studio break,Android Studio IDE: Break on Exception

可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效&#xff0c;请关闭广告屏蔽插件后再试):问题:It seems my Android Studio does not want to break on any exception by default. Enabling break on "Any Exception" starts breaking within act…

php查到的内容追加到html,javascript - 请问php中如何将查询出来的结果数组转化成自己想要的格式,并在前台利用js输出到html中...

考试类型的表jx_exam_type&#xff0c;可后台添加内容考试成绩的表jx_result&#xff0c;可后台添加内容期中考试成绩表中的exam_id对应考试类型表中的id&#xff0c;也就是添加的成绩是属于期中还是期末然后使用php查询$sql"SELECT re.type, re.score, re.exam_id, et.ti…

springboot页面中静态图片路径

目录结构&#xff1a; 不写th:src"{/images/a.jpeg}"是访问不到的

html字居右垂直设置,css文字水平垂直居中怎么设置?

css文字水平垂直居中怎么设置&#xff1f;下面本篇文章就来给大家介绍使用CSS设置文字水平居中和垂直居中的方法。有一定的参考价值&#xff0c;有需要的朋友可以参考一下&#xff0c;希望对大家有所帮助。1、文字水平居中在CSS中想要让文字水平居中&#xff0c;可以使用text-a…

计算机主机声音怎么办,电脑主机声音大怎么解决 电脑主机嗡嗡响是怎么回事...

如果你经常使用电脑&#xff0c;那么主机声音大的情况你肯定遇到过&#xff0c;这就是电脑老化的表现&#xff0c;说明主机内部有了很多灰尘&#xff0c;如果平时没有注意保养&#xff0c;那么就会早主机声音很大的问题&#xff0c;怎么解决呢?很简单&#xff0c;清理主机吧&a…