summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2015-04-27 20:39:37 -0700
committerJason Ekstrand <[email protected]>2015-05-08 17:16:13 -0700
commitaddcf41066d28a5d2d5ed112a65a3958b056bd19 (patch)
treefb14ba22204a837faee9047c01d4c53ae7b70995
parentb31d8983ba5d68f3bcb5520b9281a4553d66fb95 (diff)
util/list: Add list_empty and list_length functions
v2: Don't use C99 when iterating over the list Acked-by: Connor Abbott <[email protected]> Reviewed-by: Rob Clark <[email protected]>
-rw-r--r--src/util/list.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/util/list.h b/src/util/list.h
index 287a4946dc6..73b6272ca19 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -38,6 +38,7 @@
#define _UTIL_LIST_H_
+#include <stdbool.h>
#include <stddef.h>
@@ -92,6 +93,20 @@ static inline void list_delinit(struct list_head *item)
item->prev = item;
}
+static inline bool list_empty(struct list_head *list)
+{
+ return list->next == list;
+}
+
+static inline unsigned list_length(struct list_head *list)
+{
+ struct list_head *node;
+ unsigned length = 0;
+ for (node = list->next; node != list; node = node->next)
+ length++;
+ return length;
+}
+
#define LIST_INITHEAD(__item) list_inithead(__item)
#define LIST_ADD(__item, __list) list_add(__item, __list)
#define LIST_ADDTAIL(__item, __list) list_addtail(__item, __list)