cyclic: switch to using hlist instead of list
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>
Fri, 28 Oct 2022 11:50:53 +0000 (13:50 +0200)
committerStefan Roese <sr@denx.de>
Wed, 2 Nov 2022 07:41:55 +0000 (08:41 +0100)
commit28968394839bec37dacf6ffc2ae880e38756e917
tree8dfb3538a21379a017537937e071c8beb7284b2d
parent2399b628f4c1c92bbe9033273b450b1e514f802e
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-*
cmd/cyclic.c
common/cyclic.c
include/cyclic.h