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))
相关推荐
杜子不疼.20 分钟前
【Linux】进程状态全解析:从 R/S/D/T 到僵尸 / 孤儿进程
linux·人工智能·ai
序属秋秋秋1 小时前
《Linux系统编程之进程基础》【进程优先级】
linux·运维·c语言·c++·笔记·进程·优先级
加勒比之杰克1 小时前
【操作系统原理】Linux 进程控制
linux·运维·服务器·进程控制
XH-hui3 小时前
【打靶日记】TheHackerLabs 之 THLPWN
linux·网络安全·thehackerlabs·thl
小兔薯了9 小时前
11. Linux firewall 防火墙管理
linux·运维·服务器
Linux技术芯10 小时前
浅谈SCSI寻址机制与工作阶段深度解析?
linux
☼←安于亥时→❦12 小时前
Linux 系统日志‘/var/log/syslog‘ 和 ‘/var/log/messages‘ 详解
linux
袁气满满~_~12 小时前
Ubuntu下配置PyTorch
linux·pytorch·ubuntu
倦王12 小时前
Linux看ip,改用户名字加权限,在单独用户下设置miniconda
linux·服务器·tcp/ip
少废话h12 小时前
Flume Kafka源与汇的topic覆盖问题解决
java·linux·kafka·flume