From e1502d862fec495b9fdd29131a30050e82c3d390 Mon Sep 17 00:00:00 2001 From: John Anthony Date: Sun, 16 Jun 2013 01:30:16 +0100 Subject: Updated list implementation --- list.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/list.h b/list.h index 936fbac..bb4473e 100644 --- a/list.h +++ b/list.h @@ -18,6 +18,8 @@ * using the generic single-entry routines. */ +#include + struct list_head { struct list_head *next, *prev; }; @@ -135,7 +137,7 @@ list_move_tail(struct list_head *list, struct list_head *head) { * list_empty - tests whether a list is empty * @head: the list to test. */ -static inline int +static inline bool list_empty(struct list_head *head) { return head->next == head; } @@ -272,4 +274,19 @@ list_splice_init(struct list_head *list, struct list_head *head) { &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +/** + * list_len - count number of elements in the given list + * @head: the head for your list + * Note: This is a O(1) time operation and should be used sparingly + */ +static inline size_t +list_len(struct list_head *head) { + struct list_head *iter; + size_t count = 0; + + list_for_each(iter, head) + ++count; + return count; +} + #endif -- cgit v1.2.3