From b51a3420b00502315e608dac0cb33917c235d277 Mon Sep 17 00:00:00 2001 From: yanghuang Date: Wed, 11 Oct 2023 17:21:09 +0800 Subject: [PATCH] =?UTF-8?q?[kernel]=20=E8=A7=A3=E5=86=B3rt=5Fslist=5Ffor?= =?UTF-8?q?=5Feach=5Fentry=E5=AE=8F=E4=B8=8D=E8=83=BD=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E9=81=8D=E5=8E=86slist=E9=93=BE=E8=A1=A8=E4=B8=AD=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 因rt_slist_for_each_entry宏不能正常调用,在实际开发中去循环再调用rt_slist_entry很不简洁,所以修改了rt_slist_for_each_entry宏中关于链表next的判空处理。目前相关代码在GD32系统的MCU上均能正常工作,相关应用也在生产产品中经过验证。 --- include/rtservice.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/rtservice.h b/include/rtservice.h index ae7e69cf5e..03301aa99a 100644 --- a/include/rtservice.h +++ b/include/rtservice.h @@ -280,9 +280,9 @@ rt_inline int rt_slist_isempty(rt_slist_t *l) * @param member the name of the list_struct within the struct. */ #define rt_slist_for_each_entry(pos, head, member) \ - for (pos = rt_slist_entry((head)->next, typeof(*pos), member); \ - &pos->member != (RT_NULL); \ - pos = rt_slist_entry(pos->member.next, typeof(*pos), member)) + for (pos = ((head)->next == (RT_NULL) ? (RT_NULL) : rt_slist_entry((head)->next, typeof(*pos), member)); \ + pos != (RT_NULL) && &pos->member != (RT_NULL); \ + pos = (pos->member.next == (RT_NULL) ? (RT_NULL) : rt_slist_entry(pos->member.next, typeof(*pos), member))) /** * rt_slist_first_entry - get the first element from a slist