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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Dmitry Torokhov <[email protected]>

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

Signed-off-by: Dmitry Torokhov <[email protected]>
---

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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux