Skip to content
Snippets Groups Projects
  • Rasmus Villemoes's avatar
    28968394
    cyclic: switch to using hlist instead of list · 28968394
    Rasmus Villemoes authored and Stefan Roese's avatar Stefan Roese committed
    
    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: default avatarRasmus Villemoes <rasmus.villemoes@prevas.dk>
    Reviewed-by: default avatarStefan Roese <sr@denx.de>
    Tested-by: default avatarStefan Roese <sr@denx.de>
    Tested-by: Tim Harvey <tharvey@gateworks.com> # imx8mm-venice-*
    28968394
    History
    cyclic: switch to using hlist instead of list
    Rasmus Villemoes authored and Stefan Roese's avatar Stefan Roese committed
    
    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: default avatarRasmus Villemoes <rasmus.villemoes@prevas.dk>
    Reviewed-by: default avatarStefan Roese <sr@denx.de>
    Tested-by: default avatarStefan Roese <sr@denx.de>
    Tested-by: Tim Harvey <tharvey@gateworks.com> # imx8mm-venice-*