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))
相关推荐
LCG元4 分钟前
考古利器:find 命令的高级用法,按时间、大小、内容精准查找
linux
U***74691 小时前
Linux(CentOS)安装 MySQL
linux·mysql·centos
3***g2051 小时前
Linux系统离线部署MySQL详细教程(带每步骤图文教程)
linux·mysql·adb
Dovis(誓平步青云)2 小时前
《内核视角下的 Linux 锁与普通生产消费模型:同步原语设计与性能优化思路》
linux·运维·性能优化
xu_yule2 小时前
Linux_13(多线程)页表详解+轻量级进程+pthread_create
linux·运维·服务器
江湖有缘4 小时前
Linux系统之htop命令基本使用
linux·运维·服务器
CodeByV4 小时前
【Linux】基础 IO 深度解析:文件、描述符与缓冲区
linux
xu_yule10 小时前
Linux_12(进程信号)内核态和用户态+处理信号+不可重入函数+volatile
linux·运维·服务器
虾..10 小时前
Linux 环境变量&&进程优先级
linux·运维·服务器
i***t91910 小时前
Linux下MySQL的简单使用
linux·mysql·adb