From c06f6943a66cff3fa20e570edc8f2aff235ae75e Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 27 Sep 2019 18:24:18 -0400 Subject: [PATCH] list: Add additional list helper functions Add list_is_first, list_is_last, list_last_entry, and list_prev_entry helper functions. Signed-off-by: Kevin O'Connor --- klippy/chelper/list.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/klippy/chelper/list.h b/klippy/chelper/list.h index 317a109c..12fe2b03 100644 --- a/klippy/chelper/list.h +++ b/klippy/chelper/list.h @@ -30,6 +30,18 @@ list_empty(const struct list_head *h) return h->root.next == &h->root; } +static inline int +list_is_first(const struct list_node *n, const struct list_head *h) +{ + return n->prev == &h->root; +} + +static inline int +list_is_last(const struct list_node *n, const struct list_head *h) +{ + return n->next == &h->root; +} + static inline void list_del(struct list_node *n) { @@ -90,9 +102,15 @@ list_join_tail(struct list_head *add, struct list_head *h) #define list_next_entry(pos, member) \ container_of((pos)->member.next, typeof(*pos), member) +#define list_prev_entry(pos, member) \ + container_of((pos)->member.prev, typeof(*pos), member) + #define list_first_entry(head, type, member) \ container_of((head)->root.next, type, member) +#define list_last_entry(head, type, member) \ + container_of((head)->root.prev, type, member) + #define list_for_each_entry(pos, head, member) \ for (pos = list_first_entry((head), typeof(*pos), member) \ ; &pos->member != &(head)->root \