From 34baff16d98c725c6e170c530f0ab72373b17a8f Mon Sep 17 00:00:00 2001 From: Boram Park Date: Wed, 11 May 2016 09:34:53 +0900 Subject: [PATCH] add LIST_LENGTH macro Change-Id: I5a64f1416aadde167a51a1ed5bcd3adeae2be12d --- include/tdm_list.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/tdm_list.h b/include/tdm_list.h index acdf6c4..a6d6bbb 100644 --- a/include/tdm_list.h +++ b/include/tdm_list.h @@ -87,12 +87,27 @@ static inline void list_delinit(struct list_head *item) item->prev = item; } +static inline int list_length(struct list_head *item) +{ + struct list_head *next; + int length = 0; + + next = item->next; + while (next != item) { + length++; + next = next->next; + } + + 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) #define LIST_REPLACE(__from, __to) list_replace(__from, __to) #define LIST_DEL(__item) list_del(__item) #define LIST_DELINIT(__item) list_delinit(__item) +#define LIST_LENGTH(__item) list_length(__item) #define LIST_ENTRY(__type, __item, __field) \ ((__type *)(((char *)(__item)) - offsetof(__type, __field))) -- 2.7.4