X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Flist.h;h=6edb750110973ed42d926a60e1cf55299236b546;hb=ce412371513c90bf9156f22c3567ee57750ef264;hp=d4b485174fc7391fc2dde6a127e7d224dc02d75f;hpb=005c8e01062e8e88a86904b955d5422742bd32e7;p=mesa.git diff --git a/src/util/list.h b/src/util/list.h index d4b485174fc..6edb7501109 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -41,6 +41,7 @@ #include #include #include +#include "c99_compat.h" struct list_head @@ -71,12 +72,18 @@ static inline void list_addtail(struct list_head *item, struct list_head *list) list->prev = item; } +static inline bool list_empty(struct list_head *list); + static inline void list_replace(struct list_head *from, struct list_head *to) { - to->prev = from->prev; - to->next = from->next; - from->next->prev = to; - from->prev->next = to; + if (list_empty(from)) { + list_inithead(to); + } else { + to->prev = from->prev; + to->next = from->next; + from->next->prev = to; + from->prev->next = to; + } } static inline void list_del(struct list_head *item) @@ -99,6 +106,14 @@ static inline bool list_empty(struct list_head *list) return list->next == list; } +/** + * Returns whether the list has exactly one element. + */ +static inline bool list_is_singular(const struct list_head *list) +{ + return list->next != NULL && list->next != list && list->next->next == list; +} + static inline unsigned list_length(struct list_head *list) { struct list_head *node;