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))
相关推荐
warton883 分钟前
ubuntu24.04 安装mysql8.0.36
linux·运维·mysql
范纹杉想快点毕业10 分钟前
嵌入式通信核心架构:从状态机、环形队列到多协议融合
linux·运维·c语言·算法·设计模式
白驹过隙^^14 分钟前
VitrualBox及ubuntu系统安装
linux·运维·ubuntu
可爱又迷人的反派角色“yang”15 分钟前
k8s(一)
linux·运维·网络·云原生·容器·kubernetes
可爱又迷人的反派角色“yang”34 分钟前
CICD持续集成Ruo-Yi项目
linux·运维·网络·ci/cd·docker·容器
大聪明-PLUS40 分钟前
一个简单高效的 C++ 监控程序,带有一个通用的 Makefile
linux·嵌入式·arm·smarc
烤鱼骑不快1 小时前
ubuntu系统安装以及设置
linux·数据库·ubuntu
HIT_Weston1 小时前
89、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(三)
linux·运维·ubuntu
白驹过隙^^1 小时前
windows通过docker compose部署oktopus服务
linux·windows·tcp/ip·docker·容器·开源
独自破碎E1 小时前
在Linux系统中怎么排查文件占用问题?
linux·运维·服务器