shl: dlist: add macros for iterating lists in reverse order
authorDavid Herrmann <dh.herrmann@googlemail.com>
Mon, 8 Oct 2012 15:15:42 +0000 (17:15 +0200)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Mon, 8 Oct 2012 15:15:42 +0000 (17:15 +0200)
These macros do the same as the already available macros but in reversed
order. This is useful when list-order is important.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/shl_dlist.h

index 17ca8b3..8887f7f 100644 (file)
@@ -109,4 +109,11 @@ static inline bool shl_dlist_empty(struct shl_dlist *head)
        for (iter = (head)->next, tmp = iter->next; iter != (head); \
                iter = tmp, tmp = iter->next)
 
+#define shl_dlist_for_each_reverse(iter, head) \
+       for (iter = (head)->prev; iter != (head); iter = iter->prev)
+
+#define shl_dlist_for_each_reverse_safe(iter, tmp, head) \
+       for (iter = (head)->prev, tmp = iter->prev; iter != (head); \
+               iter = tmp, tmp = iter->prev)
+
 #endif /* SHL_DLIST_H */