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))
相关推荐
bush415 小时前
正点原子imx6ull-uboot,奇怪的问题
linux·学习
dddwjzx15 小时前
嵌入式Linux C应用编程——Framebuffer应用编程
linux·嵌入式
今天也想躺ping17 小时前
linux系统移植pjsua库实现sip通话功能
linux·sip·交叉编译
hkj880818 小时前
Linux 总线-设备-驱动(Bus-Device-Driver)完整协作原理
linux·运维·microsoft
早点睡啊Y18 小时前
深入学 LangChain 官方文档(一):总览、安装与快速开始
linux·服务器·langchain
一直在努力学习的菜鸟18 小时前
Rocky8.5编译安装PHP8.4
linux·运维
国产化创客19 小时前
Kindle完整越狱改造:从闲置泡面盖到Linux开发与智能家居终端
linux·运维·物联网·嵌入式·智能家居·智能硬件
qetfw19 小时前
CentOS 7 搭建 MariaDB 数据库服务
linux·数据库·centos·mariadb
皮卡狮20 小时前
进程的地址空间
linux
Darkwanderor20 小时前
动、静态库相关内容的详细介绍
linux·c语言·开发语言·c++