X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Flist.h;h=f0dec5da60874c7cf9e6028589e9d1f03697816b;hb=cf375a3333e54a01462f192202d609436e5fbec8;hp=946034710efd6e11b70b9645458ff3d8f39b6a75;hpb=2c2cd368aad9167816547aa86009c9cb489255c0;p=mesa.git diff --git a/src/util/list.h b/src/util/list.h index 946034710ef..f0dec5da608 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -99,6 +99,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->next == list; +} + static inline unsigned list_length(struct list_head *list) { struct list_head *node; @@ -108,6 +116,28 @@ static inline unsigned list_length(struct list_head *list) return length; } +static inline void list_splice(struct list_head *src, struct list_head *dst) +{ + if (list_empty(src)) + return; + + src->next->prev = dst; + src->prev->next = dst->next; + dst->next->prev = src->prev; + dst->next = src->next; +} + +static inline void list_splicetail(struct list_head *src, struct list_head *dst) +{ + if (list_empty(src)) + return; + + src->prev->next = dst; + src->next->prev = dst->prev; + dst->prev->next = src->next; + dst->prev = src->prev; +} + static inline void list_validate(struct list_head *list) { struct list_head *node; @@ -140,6 +170,13 @@ static inline void list_validate(struct list_head *list) - ((char *)&(sample)->member - (char *)(sample))) #endif +#define list_first_entry(ptr, type, member) \ + LIST_ENTRY(type, (ptr)->next, member) + +#define list_last_entry(ptr, type, member) \ + LIST_ENTRY(type, (ptr)->prev, member) + + #define LIST_FOR_EACH_ENTRY(pos, head, member) \ for (pos = NULL, pos = container_of((head)->next, pos, member); \ &pos->member != (head); \