linux内核学习中--"list.h" del move splice 函数理解
来源:互联网 发布:软件无线电技术应用 编辑:程序博客网 时间:2024/06/06 03:52
第三篇博客,主要是针对删除,移动,合并函数的理解,很简单的,相信大家一看就明白了。
static inline void __list_del(struct list_head * prev, struct list_head * next) //删除结点。删除链表中prev与next之间的元素{ next->prev = prev; prev->next = next;}static inline void list_del(struct list_head *entry) //删除一个结点entry,并将删除结点地址置为0{ __list_del(entry->prev, entry->next); entry->next = LIST_POISON1; //指针清除0 entry->prev = LIST_POISON2; //指针清除0}static inline void list_del_init(struct list_head *entry) //从链表中删除元素entry,并将其初始化为新的链表。{ __list_del(entry->prev, entry->next); INIT_LIST_HEAD(entry); //初始化就是把指针指向自己 }static inline void list_move(struct list_head *list, struct list_head *head) //将该结点摘除并插入到链表头部{ __list_del(list->prev, list->next); list_add(list, head);}static inline void list_move_tail(struct list_head *list, //将该结点摘除并插入到链表尾部部 struct list_head *head){ __list_del(list->prev, list->next); list_add_tail(list, head);}static inline int list_empty(const struct list_head *head) //测试链表是否为空{ return head->next == head;}static inline int list_empty_careful(const struct list_head *head) { struct list_head *next = head->next; return (next == head) && (next == head->prev);}/*基本的list_empty()仅以头指针的next是否指向自己来判断链表是否为空,Linux链表另行提供了一个list_empty_careful()宏,它同时判断头指针的next和prev,仅当两者都指向自己时才返回真。这主要是为了应付另一个cpu正在处理同一个链表而造成next、prev不一致的情况。但代码注释也承认,这一安全保障能力有限:除非其他cpu的链表操作只有list_del_init(),否则仍然不能保证安全,也就是说,还是需要加锁保护。*/static inline void __list_splice(struct list_head *list, //合并链表, 将链表list与head合并。 struct list_head *head){ struct list_head *first = list->next; struct list_head *last = list->prev; struct list_head *at = head->next; first->prev = head; head->next = first; last->next = at; at->prev = last;}/*** list_splice - join two lists* @list: the new list to add.* @head: the place to add it in the first list.*/static inline void list_splice(struct list_head *list, struct list_head *head) //list不为空的情况下,调用__list_splice()实现list与head的合并{ if (!list_empty(list)) __list_splice(list, head);}/*** list_splice_init - join two lists and reinitialise the emptied list.* @list: the new list to add.* @head: the place to add it in the first list.** The list at @list is reinitialised*/static inline void list_splice_init(struct list_head *list, //将两链表合并,并将list初始化。 struct list_head *head){ if (!list_empty(list)) { __list_splice(list, head); INIT_LIST_HEAD(list); }}
- linux内核学习中--"list.h" del move splice 函数理解
- linux内核学习中--“list.h”中 插入add函数 总结
- linux内核学习中--“list.h”文件中 hlist所有函数与宏定义的详解
- linux内核list.h的学习
- linux内核list.h
- linux内核list.h
- linux内核学习中-- 史上最全 linux通用链表“list.h”详解
- list::splice()函数详解
- list::splice()函数详解
- list 的 splice 函数
- list::splice()函数详解
- list::splice()函数详解
- list::splice()函数详解
- list::splice()函数详解
- linux 内核之 list.h
- linux内核list.h中对链表的操作
- linux内核 kthread_run函数 理解学习
- linux内核 kthread_run函数 理解学习
- 主动积极一点,脸皮再厚点…
- ESFramework 开发手册(09) -- ACK机制与同步调用
- 微诺“新婚”一年:相濡以沫 前路未知
- Linux网络驱动程序编写
- GDB资源
- linux内核学习中--"list.h" del move splice 函数理解
- Magento首页添加幻灯片教程
- mongodb关于时间date的查询——Querying for a Date Range
- ESFramework 开发手册(10) -- 安全机制
- Magento任意页面添加Contact Us表单
- C++ 回忆录1
- English - 常用口语
- log4cpp在项目中的封装使用(VC项目)
- getopt 分析命令行参数