[Mesa-dev] [PATCH 01/70] util/list: Add convenience functions for moving a list element

Martin Peres martin.peres at linux.intel.com
Mon Aug 10 04:13:54 PDT 2015


On 07/08/15 23:13, Chris Wilson wrote:
> Just a couple of functions for removing an element from one list and
> adding to another (perhaps even the same list, just at the head or
> tail).
>
> Used in future patches.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>   src/util/list.h | 27 +++++++++++++++++++++------
>   1 file changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/src/util/list.h b/src/util/list.h
> index b98ce59..cce1adc 100644
> --- a/src/util/list.h
> +++ b/src/util/list.h
> @@ -55,6 +55,12 @@ static inline void list_inithead(struct list_head *item)
>       item->next = item;
>   }
>   
> +static inline void __list_del(struct list_head *item)
> +{
> +    item->prev->next = item->next;
> +    item->next->prev = item->prev;
> +}
> +
>   static inline void list_add(struct list_head *item, struct list_head *list)
>   {
>       item->prev = list;
> @@ -63,6 +69,12 @@ static inline void list_add(struct list_head *item, struct list_head *list)
>       list->next = item;
>   }
>   
> +inline static void list_move(struct list_head *from, struct list_head *to)
> +{
> +   __list_del(from);
> +   list_add(from, to);
> +}
> +
>   static inline void list_addtail(struct list_head *item, struct list_head *list)
>   {
>       item->next = list;
> @@ -71,6 +83,12 @@ static inline void list_addtail(struct list_head *item, struct list_head *list)
>       list->prev = item;
>   }
>   
> +inline static void list_movetail(struct list_head *from, struct list_head *to)
> +{
> +   __list_del(from);
> +   list_addtail(from, to);
> +}
> +
>   static inline void list_replace(struct list_head *from, struct list_head *to)
>   {
>       to->prev = from->prev;
> @@ -81,17 +99,14 @@ static inline void list_replace(struct list_head *from, struct list_head *to)
>   
>   static inline void list_del(struct list_head *item)
>   {
> -    item->prev->next = item->next;
> -    item->next->prev = item->prev;
> +   __list_del(item);
>       item->prev = item->next = NULL;
>   }
>   
>   static inline void list_delinit(struct list_head *item)
>   {
> -    item->prev->next = item->next;
> -    item->next->prev = item->prev;
> -    item->next = item;
> -    item->prev = item;
> +   __list_del(item);
> +   list_inithead(item);
>   }
>   
>   static inline bool list_empty(struct list_head *list)

Nice cleanup on top of the adding the new convenience functions. I don't 
mind having both in one patch but it would be nice adding that you do 
this cleanup :) With the updated commit message:

Reviewed-by: Martin Peres <martin.peres at linux.intel.com>


More information about the mesa-dev mailing list