linux内核的一些宏

目录

1、list_add_tail

c 复制代码
/*!
 * @brief list_add_tail - add a new entry
 *
 * @details Insert a new entry before the specified head.
 * This is useful for implementing queues.
 *
 * @param new_h: new entry to be added
 * @param head: list head to add it before
 */
static inline void list_add_tail(struct list_head *new_h, struct list_head *head)
{
	__list_add(new_h, head->prev, head);
}
/*!
 * @brief Insert a new entry between two known consecutive entries.
 *
 * @details This is only for internal list manipulation where we know
 * the prev/next entries already!
 */
static inline void __list_add(struct list_head *new_h,
				  struct list_head *prev,
				  struct list_head *next)
{
	next->prev = new_h;
	new_h->next = next;
	new_h->prev = prev;
	prev->next = new_h;
}

2、list_for_each_entry

c 复制代码
#define list_for_each_entry(pos, head, member)				\
	for (pos = list_first_entry(head, typeof(*pos), member);	\
		 &pos->member != (head);					\
		 pos = list_next_entry(pos, member))
		 
#define list_first_entry(ptr, type, member) \
	list_entry((ptr)->next, type, member)
	
#define list_entry(ptr, type, member) \
	container_of(ptr, type, member)
	
#define list_next_entry(pos, member) \
	list_entry((pos)->member.next, typeof(*(pos)), member)
	
//宏展开
for (pos = container_of((head)->next, typeof(*pos), member);
	&pos->member != (head);
	pos = container_of((pos)->member.next, typeof(*(pos)), member))
相关推荐
LaoWaiHang32 分钟前
Linux基础知识13:用户、用户组管理
linux
Coder个人博客2 小时前
Linux6.19-ARM64 mm init子模块深入分析
linux·安全·车载系统·系统架构·系统安全·鸿蒙系统·安全架构
济6172 小时前
ARM Linux 驱动开发篇----Linux驱动开发与裸机开发的区别---- Ubuntu20.04
linux·arm开发·驱动开发
慎思知行2 小时前
Discord中创建机器人的流程
linux·服务器·机器人
enbug2 小时前
编译安卓内核:以坚果R1、魔趣MK100(Android 10)系统为例
android·linux
玉梅小洋2 小时前
Linux命令详解 —— IP 命令及永久配置
linux·运维·tcp/ip
江畔何人初2 小时前
k8s中Role与networkpolicy区别
linux·运维·云原生
Madison-No72 小时前
【Linux】一切皆文件的理解 && 缓冲区 && 简易设计libc库
linux·运维·服务器
快来吃饭�2 小时前
Ubuntu-20.04 gem5 构建并实现一个简单的配置脚本
linux·ubuntu·系统架构
daemon.qiang3 小时前
mplayer使能支持vaapi
linux·centos