linux内核学习中--“list.h”中 插入add函数 总结
来源:互联网 发布:东亚文化圈知乎 编辑:程序博客网 时间:2024/05/20 18:49
第一 声明和初始化,我在这里不详细说明了,请看我上一篇博文,在这里贴出相应的代码:
#ifndef _LINUX_LIST_H#define _LINUX_LIST_H#define offsetof1(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)#define container_of(ptr, type, member) ( { \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof1(type,member) ); } )static inline void prefetch(const void *x) {;}static inline void prefetchw(const void *x) {;}//#define LIST_POISON1 ((void *) 0x00100100)//#define LIST_POISON2 ((void *) 0x00200200)#define LIST_POISON1 0#define LIST_POISON2 0struct list_head { struct list_head *next, *prev; //双向链表};#define LIST_HEAD_INIT(name) { &(name), &(name) } //用同一对象初始化next 和prev.#define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name)#define INIT_LIST_HEAD(ptr) do { \ //初始化就是把指针指向自己 (ptr)->next = (ptr); (ptr)->prev = (ptr); \} while (0)
下面就是插入函数的具体分析,其实插入函数很简单,只要学过C语言的都能懂,我在这里只是简单解释下:
/** 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 *new1, //插入新条目,插在prev与next中间 struct list_head *prev, // struct list_head *next){ next->prev = new1; new1->next = next; new1->prev = prev; prev->next = new1;}/*** 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.*/static inline void list_add(struct list_head *new1, struct list_head *head) //头插法,调用_list_add()实现{ __list_add(new1, 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 *new1, struct list_head *head) //尾部插法{ __list_add(new1, head->prev, head);}
- linux内核学习中--“list.h”中 插入add函数 总结
- linux内核学习中--“list.h”文件中 hlist所有函数与宏定义的详解
- linux内核学习中--"list.h" del move splice 函数理解
- linux内核学习中-- 史上最全 linux通用链表“list.h”详解
- linux内核list.h中对链表的操作
- linux中list.h中函数应用实例
- linux内核list.h的学习
- linux内核list.h
- linux内核list.h
- Linux内核中监听网线是否插入是否工作函数
- Linux内核链表定义在include/linux/list.h文件中
- linux 2.4内核中双向链表的实现/include/linux/list.h
- Linux 内核中双向链表及list.h 文件分析
- linux内核中的list.h文件中线性链表的分析(一)
- linux内核中的list.h文件中线性链表的分析(二)
- linux 内核之 list.h
- list add方法学习总结
- linux内核List中关于hash链表
- 分享百度网盘邀请码十个
- 使用超链接实现数据钻取
- oracle复合类型---嵌套表模糊查询
- Vi中内容查找
- ESFramework 开发手册(02) -- 基础功能与状态通知
- linux内核学习中--“list.h”中 插入add函数 总结
- 一些简单常用的正则表达式
- 开机过程中两个Activity优先级冲突
- 在戴尔服务器上安装linux
- 苹果官方指南:Cocoa框架(1)
- 【C++ primer】高效的逻辑运算符
- ESFramework 开发手册(03)--文件(夹)传送
- 苹果官方指南:Cocoa框架(2)
- VBA 工作表的添加与删除