CI: https://dev.azure.com/sr0718/u-boot/_build/results?buildId=393&view=results

- make cyclic_(un)register idempotent
This commit is contained in:
Tom Rini
2025-05-16 11:05:27 -06:00
2 changed files with 30 additions and 0 deletions

View File

@@ -28,9 +28,23 @@ struct hlist_head *cyclic_get_list(void)
return (struct hlist_head *)&gd->cyclic_list;
}
static bool cyclic_is_registered(const struct cyclic_info *cyclic)
{
const struct cyclic_info *c;
hlist_for_each_entry(c, cyclic_get_list(), list) {
if (c == cyclic)
return true;
}
return false;
}
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 */
@@ -43,6 +57,9 @@ void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
void cyclic_unregister(struct cyclic_info *cyclic)
{
if (!cyclic_is_registered(cyclic))
return;
hlist_del(&cyclic->list);
}

View File

@@ -54,3 +54,16 @@ responsible for calling all registered cyclic functions, into the
common schedule() function. This guarantees that cyclic_run() is
executed very often, which is necessary for the cyclic functions to
get scheduled and executed at their configured periods.
Idempotence
-----------
Both the cyclic_register() and cyclic_unregister() functions are safe
to call on any struct cyclic_info, regardless of whether that instance
is already registered or not.
More specifically, calling cyclic_unregister() with a cyclic_info
which is not currently registered is a no-op, while calling
cyclic_register() with a cyclic_info which is currently registered
results in it being automatically unregistered, and then registered
with the new callback function and timeout parameters.