From 6d36a2fc9f1b378302aaaab9e931eff2e7db4c46 Mon Sep 17 00:00:00 2001 From: yangwei Date: Thu, 19 Sep 2024 16:56:52 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(utils.h=20add=20count=5Fof):?= =?UTF-8?q?=20mq=20clean=20using=20count=5Fof?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/stellar/utils.h | 4 ++++ infra/mq/mq.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/stellar/utils.h b/include/stellar/utils.h index 3d6ab43..16fd318 100644 --- a/include/stellar/utils.h +++ b/include/stellar/utils.h @@ -35,6 +35,10 @@ (type *)( (char *)__mptr - offsetof(type,member) ); }) #endif +#ifndef count_of +#define count_of(x) (sizeof(x) / sizeof(0 [x])) +#endif + #ifndef likely #define likely(x) __builtin_expect((x), 1) #endif /* likely */ diff --git a/infra/mq/mq.c b/infra/mq/mq.c index a0e87f6..aca3d73 100644 --- a/infra/mq/mq.c +++ b/infra/mq/mq.c @@ -135,7 +135,7 @@ void mq_runtime_clean(struct mq_runtime *rt) struct mq_topic *topic; rt->publish_enabled=false; - for (int i = 0; i < STELLAR_MQ_MAX; i++) + for (unsigned long i = 0; i < count_of(rt->priority_mq); i++) { DL_FOREACH_SAFE(rt->priority_mq[i], mq_elt, tmp) {