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))
相关推荐
顺顺 尼9 小时前
linux 进程信号(上)
linux·c++·算法
niuTaylor9 小时前
飞腾 FT-2000/4 Ubuntu 内存卡 / NVMe SSD 系统制作完整指南
linux·服务器·人工智能·驱动开发·单片机
傲世仙尊10 小时前
信号量环形队列与线程池起步-把临界资源拆成很多份
linux
Huangjin007_11 小时前
【Linux 系统篇(二十五)】文件(二) 系统文件I/O详解
linux·运维·服务器
ShineWinsu11 小时前
对于ProtoBuffer:ProtoBuffer的介绍以及安装
linux·网络·google·协议·序列化·反序列化·protobuffer
FlightYe12 小时前
视界原理之2D视频(二):视频文件里有什么
android·linux·网络·c++·ffmpeg·音视频·aac
GeW13 小时前
从代码到共识:技术突围如何映照大国相处之道
linux
承渊政道14 小时前
Linux系统学习【进程信号详细解析——认识、产生、保存以及捕捉信号】
linux·学习·ubuntu·ssh·vs code·进程信号
硅基手札14 小时前
【linux内核专栏01】Linux 内核心智模型与设计哲学
linux·运维·驱动开发·开源软件
码完就睡15 小时前
Linux——socket网络编程
linux·运维·网络