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))
相关推荐
peterhunter032013 小时前
CONFIG_CPU_SW_DOMAIN_PAN
linux
zfj32113 小时前
Linux 系统 I/O 监控命令大全
linux·服务器·数据库·io·监控
___波子 Pro Max.13 小时前
Linux下的posix_spawn接口使用场景及与fork区别
linux
oMcLin13 小时前
Linux 系统服务器的 KVM 虚拟化实战:搭建、配置与管理
linux·运维·服务器
飞Link13 小时前
【Hive】Linux(CentOS7)下安装Hive教程
大数据·linux·数据仓库·hive·hadoop
TPBoreas14 小时前
清理服务器日志空间
linux·运维·服务器
Howrun77714 小时前
Linux进程通信---1---匿名管道
linux
天骄t14 小时前
HTML入门:从基础结构到表单实战
linux·数据库
大聪明-PLUS14 小时前
了解 Linux 系统中用于流量管理的 libnl 库
linux·嵌入式·arm·smarc
食咗未14 小时前
Linux USB HOST EXTERNAL VIRTUAL COM PORT
linux·驱动开发