From: Dmitry Torokhov <dtor@insightbb.com>
To: Arjan van de Ven <arjan@infradead.org>
Cc: Andi Kleen <ak@suse.de>, Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [RFC/PATCH] Introduce list_get() and list_get_tail()
Date: Sat, 8 Jul 2006 23:28:47 -0400 [thread overview]
Message-ID: <200607082328.48575.dtor@insightbb.com> (raw)
In-Reply-To: <1152368186.3120.50.camel@laptopd505.fenrus.org>
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
next prev parent reply other threads:[~2006-07-09 3:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-08 5:24 [RFC/PATCH] Introduce list_get() and list_get_tail() Dmitry Torokhov
2006-07-08 13:58 ` Andi Kleen
2006-07-08 14:16 ` Arjan van de Ven
2006-07-08 17:02 ` Matthieu CASTET
2006-07-09 3:28 ` Dmitry Torokhov [this message]
2006-07-11 17:43 ` Josef Sipek
2006-07-11 17:58 ` Dmitry Torokhov
2006-07-08 18:31 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200607082328.48575.dtor@insightbb.com \
--to=dtor@insightbb.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=arjan@infradead.org \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox