我们从2011年坚守至今,只想做存粹的技术论坛。  由于网站在外面,点击附件后要很长世间才弹出下载,请耐心等待,勿重复点击不要用Edge和IE浏览器下载,否则提示不安全下载不了

 找回密码
 立即注册
搜索
查看: 1162|回复: 0

linux内核双向链表源码分析-ARM

[复制链接]

该用户从未签到

1万

主题

1292

回帖

936

积分

管理员

积分
936

社区居民最爱沙发原创达人社区明星终身成就奖优秀斑竹奖宣传大使奖特殊贡献奖

QQ
发表于 2013-7-30 19:13:15 | 显示全部楼层 |阅读模式
1. 双向链表定义:在内核include/linux/types.h里定义了双向链表结构体类型:Struct list_head{ Struct list_head *next,*prev;};2. 链表处理2.1:链表初始化:#define LIST_HEAD_INIT(name) { &(name), &(name) }#define LIST_HEAD(name)  struct list_head name = LIST_HEAD_INIT(name)通过LIST_HEAD(list_name)宏申明并初始化2.2:添加元素:2.2.1:list_add(struct list_head *new, struct list_head *head)在现存的head元素之后,紧接着插入new元素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;}static inline void list_add(struct list_head *new, struct list_head *head){ __list_add(new, head, head->next);}2.2.2:list_add_tail(struct list_head *new, struct list_head *head)在现存数据之前添加数据static inline void list_add_tail(struct list_head *new, struct list_head *head){ __list_add(new, head->prev, head);}2.3删除数据:static inline void __list_del(struct list_head * prev, struct list_head * next){ next->prev = prev; prev->next = next;}static inline void list_del(struct list_head *entry){ __list_del(entry->prev, entry->next); entry->next = LIST_POISON1; entry->prev = LIST_POISON2;}2.4.检测链表是否为空static inline int list_empty(const struct list_head *head){ return head->next == head;}2.5. 合并两个链表static inline void __list_splice(const struct list_head *list, struct list_head *prev, struct list_head *next){ struct list_head *first = list->next; struct list_head *last = list->prev; first->prev = prev; prev->next = first; last->next = next; next->prev = last;}static inline void list_splice(const struct list_head *list, struct list_head *head){ if (!list_empty(list)) __list_splice(list, head, head->next);}2.6:查找链表元素:#define list_entry(ptr, type, member)  container_of(ptr, type, member)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

论坛开启做任务可以
额外奖励金币快速赚
积分升级了


Copyright ©2011-2024 NTpcb.com All Right Reserved.  Powered by Discuz! (NTpcb)

本站信息均由会员发表,不代表NTpcb立场,如侵犯了您的权利请发帖投诉

平平安安
TOP
快速回复 返回顶部 返回列表