OSDN Git Service

list: add first/last entry macros
authorRob Clark <robclark@freedesktop.org>
Tue, 21 Jun 2016 15:33:30 +0000 (11:33 -0400)
committerRob Clark <robclark@freedesktop.org>
Wed, 20 Jul 2016 23:42:21 +0000 (19:42 -0400)
Signed-off-by: Rob Clark <robclark@freedesktop.org>
util_double_list.h

index 27e0761..5d01f52 100644 (file)
@@ -98,6 +98,12 @@ static inline void list_delinit(struct list_head *item)
 #define LIST_ENTRY(__type, __item, __field)   \
     ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
 
+#define LIST_FIRST_ENTRY(__ptr, __type, __field)   \
+    LIST_ENTRY(__type, (__ptr)->next, __field)
+
+#define LIST_LAST_ENTRY(__ptr, __type, __field)   \
+    LIST_ENTRY(__type, (__ptr)->prev, __field)
+
 #define LIST_IS_EMPTY(__list)                   \
     ((__list)->next == (__list))