[Mesa-dev] [PATCH 2/3] util: Add list_is_single() helper function

Eduardo Lima Mitev elima at igalia.com
Fri Oct 23 08:55:19 PDT 2015


Returns true is the list has exactly one element, otherwise returns false.
---
 src/util/list.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/util/list.h b/src/util/list.h
index b98ce59..2b03461 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -99,6 +99,14 @@ static inline bool list_empty(struct list_head *list)
    return list->next == list;
 }
 
+/**
+ * Return true is the list has exactly one element, otherwise return false.
+ */
+static inline bool list_is_single(struct list_head *list)
+{
+   return list->next != NULL && list->next->next == list;
+}
+
 static inline unsigned list_length(struct list_head *list)
 {
    struct list_head *node;
-- 
2.5.3



More information about the mesa-dev mailing list