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 <kevin@koconnor.net>
This commit is contained in:
parent
fdbdb3c707
commit
c06f6943a6
|
@ -30,6 +30,18 @@ list_empty(const struct list_head *h)
|
||||||
return h->root.next == &h->root;
|
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
|
static inline void
|
||||||
list_del(struct list_node *n)
|
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) \
|
#define list_next_entry(pos, member) \
|
||||||
container_of((pos)->member.next, typeof(*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) \
|
#define list_first_entry(head, type, member) \
|
||||||
container_of((head)->root.next, 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) \
|
#define list_for_each_entry(pos, head, member) \
|
||||||
for (pos = list_first_entry((head), typeof(*pos), member) \
|
for (pos = list_first_entry((head), typeof(*pos), member) \
|
||||||
; &pos->member != &(head)->root \
|
; &pos->member != &(head)->root \
|
||||||
|
|
Loading…
Reference in New Issue