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))
相关推荐
stella·10 分钟前
服务器割接,我所学习到的内容。
linux·运维·服务器·学习·shell·割接
胡萝卜3.015 分钟前
Linux包管理器:高效安装软件的秘诀
linux·运维·服务器·人工智能·linux包管理·yum教程·apt入门
I · T · LUCKYBOOM18 分钟前
iptables 防火墙(二)
linux·运维·服务器·网络·安全·centos
带鱼吃猫24 分钟前
Linux 守护进程:会话、终端与后台运行的底层逻辑
linux·运维·服务器
wdfk_prog27 分钟前
[Linux]学习笔记系列 -- [fs]iomap
linux·笔记·学习
两拆27 分钟前
Linux(redhat7.9)安装KVM虚拟机
linux
Alex Cafu29 分钟前
Linux网络编程2(HTTP 协议、IO 多路复用)
linux·c语言·网络·http
yBmZlQzJ38 分钟前
第二篇:Linux服务器性能优化实战技巧(提升稳定性与效率)
linux·服务器·性能优化
QT 小鲜肉39 分钟前
【Linux命令大全】001.文件管理之mlabel命令(实操篇)
linux·运维·服务器·前端·笔记
知识分享小能手1 小时前
Ubuntu入门学习教程,从入门到精通, Ubuntu 22.04 的磁盘存储管理(10)
linux·学习·ubuntu