#462·kcp

[Minor] IQUEUE的两个遍历宏命名写反了,参考Linux内核的list_for_each和list_for_each_entry的命名语义

Author: coderzhangstCreated Sep 24, 2026Updated Sep 24, 2026

list_for_each和list_for_each_entry参见https://github.com/torvalds/linux/blob/master/include/linux/list.h

c
/**
 * list_for_each	-	iterate over a list
 * @pos:	the &struct list_head to use as a loop cursor.
 * @head:	the head for your list.
 */
#define list_for_each(pos, head) \
	for (pos = (head)->next; !list_is_head(pos, (head)); pos = pos->next)

/**
 * list_for_each_entry	-	iterate over list of given type
 * @pos:	the type * to use as a loop cursor.
 * @head:	the head for your list.
 * @member:	the name of the list_head within the struct.
 */
#define list_for_each_entry(pos, head, member)				\
	for (pos = list_first_entry(head, typeof(*pos), member);	\
	     !list_entry_is_head(pos, head, member);			\
	     pos = list_next_entry(pos, member))

KCP的实现

c
#define IQUEUE_FOREACH(iterator, head, TYPE, MEMBER) \ //仿照Linux内核的list_for_each_entry宏
	for ((iterator) = iqueue_entry((head)->next, TYPE, MEMBER); \
		&((iterator)->MEMBER) != (head); \
		(iterator) = iqueue_entry((iterator)->MEMBER.next, TYPE, MEMBER))

#define iqueue_foreach_entry(pos, head) \ //仿照Linux内核的list_for_each宏
	for( (pos) = (head)->next; (pos) != (head) ; (pos) = (pos)->next )