diff options
author | Rasmus Villemoes <rasmus.villemoes@prevas.dk> | 2022-10-28 13:50:53 +0200 |
---|---|---|
committer | Stefan Roese <sr@denx.de> | 2022-11-02 08:41:55 +0100 |
commit | 28968394839bec37dacf6ffc2ae880e38756e917 (patch) | |
tree | 8dfb3538a21379a017537937e071c8beb7284b2d /common | |
parent | 2399b628f4c1c92bbe9033273b450b1e514f802e (diff) | |
download | u-boot-28968394839bec37dacf6ffc2ae880e38756e917.zip u-boot-28968394839bec37dacf6ffc2ae880e38756e917.tar.gz u-boot-28968394839bec37dacf6ffc2ae880e38756e917.tar.bz2 |
cyclic: switch to using hlist instead of list
A hlist is headed by just a single pointer, so can only be traversed
forwards, and insertions can only happen at the head (or before/after
an existing list member). But each list node still consists of two
pointers, so arbitrary elements can still be removed in O(1).
This is precisely what we need for the cyclic_list - we never need to
traverse it backwards, and the order the callbacks appear in the list
should really not matter.
One advantage, and the main reason for doing this switch, is that an
empty list is represented by a NULL head pointer, so unlike a
list_head, it does not need separate C code to initialize - a
memset(,0,) of the containing structure is sufficient.
This is mostly mechanical:
- The iterators are updated with an h prefix, and the type of the
temporary variable changed to struct hlist_node*.
- Adding/removing is now just hlist_add_head (and not tail) and
hlist_del().
- struct members and function return values updated.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Stefan Roese <sr@denx.de>
Tested-by: Stefan Roese <sr@denx.de>
Tested-by: Tim Harvey <tharvey@gateworks.com> # imx8mm-venice-*
Diffstat (limited to 'common')
-rw-r--r-- | common/cyclic.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/common/cyclic.c b/common/cyclic.c index d6f11b0..32d9bf0 100644 --- a/common/cyclic.c +++ b/common/cyclic.c @@ -20,7 +20,7 @@ DECLARE_GLOBAL_DATA_PTR; void hw_watchdog_reset(void); -struct list_head *cyclic_get_list(void) +struct hlist_head *cyclic_get_list(void) { return &gd->cyclic->cyclic_list; } @@ -47,14 +47,14 @@ struct cyclic_info *cyclic_register(cyclic_func_t func, uint64_t delay_us, cyclic->name = strdup(name); cyclic->delay_us = delay_us; cyclic->start_time_us = timer_get_us(); - list_add_tail(&cyclic->list, &gd->cyclic->cyclic_list); + hlist_add_head(&cyclic->list, &gd->cyclic->cyclic_list); return cyclic; } int cyclic_unregister(struct cyclic_info *cyclic) { - list_del(&cyclic->list); + hlist_del(&cyclic->list); free(cyclic); return 0; @@ -62,7 +62,8 @@ int cyclic_unregister(struct cyclic_info *cyclic) void cyclic_run(void) { - struct cyclic_info *cyclic, *tmp; + struct cyclic_info *cyclic; + struct hlist_node *tmp; uint64_t now, cpu_time; /* Prevent recursion */ @@ -70,7 +71,7 @@ void cyclic_run(void) return; gd->flags |= GD_FLG_CYCLIC_RUNNING; - list_for_each_entry_safe(cyclic, tmp, &gd->cyclic->cyclic_list, list) { + hlist_for_each_entry_safe(cyclic, tmp, &gd->cyclic->cyclic_list, list) { /* * Check if this cyclic function needs to get called, e.g. * do not call the cyclic func too often @@ -118,9 +119,10 @@ void schedule(void) int cyclic_uninit(void) { - struct cyclic_info *cyclic, *tmp; + struct cyclic_info *cyclic; + struct hlist_node *tmp; - list_for_each_entry_safe(cyclic, tmp, &gd->cyclic->cyclic_list, list) + hlist_for_each_entry_safe(cyclic, tmp, &gd->cyclic->cyclic_list, list) cyclic_unregister(cyclic); return 0; @@ -135,7 +137,7 @@ int cyclic_init(void) return -ENOMEM; memset(gd->cyclic, '\0', size); - INIT_LIST_HEAD(&gd->cyclic->cyclic_list); + INIT_HLIST_HEAD(&gd->cyclic->cyclic_list); return 0; } |