lkml.org 
[lkml]   [2006]   [Jul]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [RFC/PATCH] Introduce list_get() and list_get_tail()
Date
On Saturday 08 July 2006 10:16, Arjan van de Ven wrote:
> On Sat, 2006-07-08 at 15:58 +0200, Andi Kleen wrote:
> > Dmitry Torokhov <dtor@insightbb.com> writes:
> >
> > > From: Dmitry Torokhov <dtor@mail.ru>
> > >
> > > Add primitives to access first and last elements of a list instead
> > > of accessng pointers directly.
> >
> > Wouldn't that be beter named list_first() and list_last() then?
> > _get is like _do and usually not very descriptive.
>
> and _get tends to imply a reference count as well; I'm with Andi on
> this.. list_first() and list_last()
>

OK, so what about the following:

Subject: Introduce primitives to get first and last list elements

Introduce list_first() and list_last(); list_first_entry() and
list_last_entry().

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---
include/linux/list.h | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+)
Index: work/include/linux/list.h
===================================================================
--- work.orig/include/linux/list.h
+++ work/include/linux/list.h
@@ -343,6 +343,26 @@ static inline void list_splice_init(stru
container_of(ptr, type, member)

/**
+ * list_first_entry - get the struct for the first entry
+ * @head: the &struct list_head pointer.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_first_entry(head, type, member) \
+ list_entry((head)->next, type, member)
+#define list_next_entry list_first_entry
+
+/**
+ * list_last_entry - get the struct for the last entry
+ * @head: the &struct list_head pointer.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_last_entry(head, type, member) \
+ list_entry((head)->prev, type, member)
+#define list_prev_entry list_last_entry
+
+/**
* list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list.
@@ -571,6 +591,26 @@ static inline void list_splice_init(stru
prefetch(rcu_dereference((pos))->next), (pos) != (head); \
(pos) = (pos)->next)

+/**
+ * list_first - get first element in a list
+ * @head: the head of your list
+ */
+#define list_next list_first
+static inline struct list_head *list_first(struct list_head *head)
+{
+ return head->next;
+}
+
+/**
+ * list_last - get last element in a list
+ * @head: the head of your list
+ */
+#define list_prev list_last
+static inline struct list_head *list_last(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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2006-07-09 05:31    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site