[Mesa-dev] [PATCH 09/13] util/list: Add list_empty and list_length functions
Jason Ekstrand
jason at jlekstrand.net
Mon Apr 27 21:03:44 PDT 2015
---
src/util/list.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/util/list.h b/src/util/list.h
index 6144b0c..246f826 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -92,6 +92,19 @@ 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)
+{
+ unsigned length = 0;
+ for (struct list_head *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)
--
2.3.6
More information about the mesa-dev
mailing list