[RFC/PATCH] Introduce list_get() and list_get_tail()

From: Dmitry Torokhov
Date: Sat Jul 08 2006 - 01:26:40 EST


From: Dmitry Torokhov <dtor@xxxxxxx>

Add primitives to access first and last elements of a list instead
of accessng pointers directly.

Signed-off-by: Dmitry Torokhov <dtor@xxxxxxx>
---

We have primitives to iterate over lists and to add/delete elements,
why not for accessing head/tail?

include/linux/list.h | 18 ++++++++++++++++++
1 files changed, 18 insertions(+)

Index: work/include/linux/list.h
===================================================================
--- work.orig/include/linux/list.h
+++ work/include/linux/list.h
@@ -571,6 +571,24 @@ static inline void list_splice_init(stru
prefetch(rcu_dereference((pos))->next), (pos) != (head); \
(pos) = (pos)->next)

+/**
+ * list_get - get first element in a list
+ * @head: the head of your list
+ */
+static inline struct list_head *list_get(struct list_head *head)
+{
+ return head->next;
+}
+
+/**
+ * list_get_tail - get last element in a list
+ * @head: the head of your list
+ */
+static inline struct list_head *list_get_tail(struct list_head *head)
+{
+ return head->prev;
+}
+
/*
* Double linked lists with a single pointer list head.
* Mostly useful for hash tables where the two pointer list head is
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/