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))
相关推荐
星恒随风7 分钟前
Linux 基础指令(三):grep、压缩打包、系统信息与 Shell 运行原理
linux·笔记·学习
Tyfrank15 分钟前
Linux内核收包路径及中断
linux·运维·单片机
男孩李36 分钟前
浅谈Linux的last命令
java·linux·服务器
yunqi39 分钟前
ELK日志平台架构详解:从Filebeat采集到Elasticsearch检索的企业级日志方案实践
linux
手揽回忆怎么睡1 小时前
Ubuntu 22.04 64位安装MinIO
linux·前端·ubuntu
阳光九叶草LXGZXJ1 小时前
达梦数据库-报错-11-cmd 13 validate error
linux·运维·数据库·sql·学习
~光~~1 小时前
【嵌入式linux学习_OV8858 bring up】L1_从Sensor到RK3588发生了什么
linux·运维·学习
Darkwanderor1 小时前
使用管道实现进程间通信 (IPC, Inter-Process Communitation)
linux·c语言·c++
Nuanyt2 小时前
Linux系统的 Shell 常见指令和常见知识点(以bash为主)
linux·运维·chrome·bash
程序员老陆2 小时前
FFmpeg 硬解在 Linux 上:从“能跑”到“跑满 GPU”的实战笔记
linux·笔记·ffmpeg