From: Rasmus Villemoes <ravi@prevas.dk>
To: u-boot@lists.denx.de
Cc: Stefan Roese <sr@denx.de>, Tom Rini <trini@konsulko.com>,
Rasmus Villemoes <ravi@prevas.dk>
Subject: [PATCH 2/3] cyclic: make cyclic_register safe to call on already-registered info
Date: Wed, 7 May 2025 12:58:20 +0200 [thread overview]
Message-ID: <20250507105821.484442-3-ravi@prevas.dk> (raw)
In-Reply-To: <20250507105821.484442-1-ravi@prevas.dk>
Now that cyclic_unregister() is safe to call on a not-registered
cyclic_info, we can make cyclic_register() behave like the mod_timer()
and hrtimer_start() APIs in linux, in that they don't distinguish
between whether the timer was already enabled or not; from the point
of the call it is, with whatever timeout/period is set in that most
recent call.
This avoids users of the cyclic API from separately keeping track of
whether their callback is already registered or not, and even if they
know it is, can be used for changing the period (and/or the callback
function) without first doing unregister().
See also this recent'ish message from kernel maintainer Thomas
Gleixner on that API design for timer frameworks:
https://lore.kernel.org/lkml/87ikn6sibi.ffs@tglx/
First of all the question is whether add() and mod() are really
valuable distinctions. I'm not convinced at all. Back then, when we
introduced hrtimers, we came to the conclusion that hrtimer_start()
is sufficient.
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---
common/cyclic.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/common/cyclic.c b/common/cyclic.c
index 75662d9f613..ec952a01ee1 100644
--- a/common/cyclic.c
+++ b/common/cyclic.c
@@ -43,6 +43,8 @@ static bool cyclic_is_registered(const struct cyclic_info *cyclic)
void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
uint64_t delay_us, const char *name)
{
+ cyclic_unregister(cyclic);
+
memset(cyclic, 0, sizeof(*cyclic));
/* Store values in struct */
--
2.49.0
next prev parent reply other threads:[~2025-05-07 10:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 10:58 [PATCH 0/3] make cyclic_(un)register idempotent Rasmus Villemoes
2025-05-07 10:58 ` [PATCH 1/3] cyclic: make cyclic_unregister() idempotent Rasmus Villemoes
2025-05-08 7:26 ` Stefan Roese
2025-05-07 10:58 ` Rasmus Villemoes [this message]
2025-05-08 7:27 ` [PATCH 2/3] cyclic: make cyclic_register safe to call on already-registered info Stefan Roese
2025-05-07 10:58 ` [PATCH 3/3] cyclic: document new guarantees for cyclic_(un)register Rasmus Villemoes
2025-05-08 7:27 ` Stefan Roese
2025-05-16 16:41 ` [PATCH 0/3] make cyclic_(un)register idempotent Stefan Roese
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250507105821.484442-3-ravi@prevas.dk \
--to=ravi@prevas.dk \
--cc=sr@denx.de \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.