[igt-dev] [PATCH i-g-t v18 01/31] lib/igt_list: igt_hlist implementation.

Chris Wilson chris at chris-wilson.co.uk
Mon Feb 1 15:34:17 UTC 2021


Quoting Zbigniew Kempczyński (2021-01-29 14:44:24)
> From: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
> 
> Double linked lists with a single pointer list head implementation,
> based on similar in the kernel.
> 
> Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
> Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  lib/igt_list.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_list.h | 50 +++++++++++++++++++++++++++++++++--
>  2 files changed, 119 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_list.c b/lib/igt_list.c
> index 5e30b19b6..60eb571c1 100644
> --- a/lib/igt_list.c
> +++ b/lib/igt_list.c
> @@ -75,3 +75,74 @@ bool igt_list_empty(const struct igt_list_head *head)
>  {
>         return head->next == head;
>  }
> +
> +void IGT_INIT_HLIST_NODE(struct igt_hlist_node *h)

void igt_hlist_init()

Fortunately the habit of calling the INIT_FUNC_ALL_CAPS
died out.

> +{
> +       h->next = NULL;
> +       h->pprev = NULL;
> +}
> +
> +int igt_hlist_unhashed(const struct igt_hlist_node *h)
> +{
> +       return !h->pprev;
> +}
> +
> +int igt_hlist_empty(const struct igt_hlist_head *h)
> +{
> +       return !h->first;
> +}
> +
> +static void __igt_hlist_del(struct igt_hlist_node *n)
> +{
> +       struct igt_hlist_node *next = n->next;
> +       struct igt_hlist_node **pprev = n->pprev;
> +
> +       *pprev = next;
> +       if (next)
> +               next->pprev = pprev;
> +}
> +
> +void igt_hlist_del(struct igt_hlist_node *n)
> +{
> +       __igt_hlist_del(n);
> +       n->next = NULL;
> +       n->pprev = NULL;
> +}
> +
> +void igt_hlist_del_init(struct igt_hlist_node *n)
> +{
> +       if (!igt_hlist_unhashed(n)) {
> +               __igt_hlist_del(n);
> +               IGT_INIT_HLIST_NODE(n);
> +       }
> +}
> +
> +void igt_hlist_add_head(struct igt_hlist_node *n, struct igt_hlist_head *h)
> +{
> +       struct igt_hlist_node *first = h->first;
> +
> +       n->next = first;
> +       if (first)
> +               first->pprev = &n->next;
> +       h->first = n;
> +       n->pprev = &h->first;
> +}
> +
> +/* next must be != NULL */
> +void igt_hlist_add_before(struct igt_hlist_node *n, struct igt_hlist_node *next)
> +{

assert next is not NULL ? Make the contractual obligations of the caller
clearer?
-Chris


More information about the igt-dev mailing list