public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC/PATCH] Introduce list_get() and list_get_tail()
@ 2006-07-08  5:24 Dmitry Torokhov
  2006-07-08 13:58 ` Andi Kleen
  2006-07-08 18:31 ` Arnd Bergmann
  0 siblings, 2 replies; 8+ messages in thread
From: Dmitry Torokhov @ 2006-07-08  5:24 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton

From: Dmitry Torokhov <dtor@mail.ru>

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

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC/PATCH] Introduce list_get() and list_get_tail()
  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 18:31 ` Arnd Bergmann
  1 sibling, 1 reply; 8+ messages in thread
From: Andi Kleen @ 2006-07-08 13:58 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Andrew Morton, linux-kernel

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.

-Andi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC/PATCH] Introduce list_get() and list_get_tail()
  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
  0 siblings, 2 replies; 8+ messages in thread
From: Arjan van de Ven @ 2006-07-08 14:16 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Dmitry Torokhov, Andrew Morton, linux-kernel

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() 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC/PATCH] Introduce list_get() and list_get_tail()
  2006-07-08 14:16   ` Arjan van de Ven
@ 2006-07-08 17:02     ` Matthieu CASTET
  2006-07-09  3:28     ` Dmitry Torokhov
  1 sibling, 0 replies; 8+ messages in thread
From: Matthieu CASTET @ 2006-07-08 17:02 UTC (permalink / raw)
  To: linux-kernel

Le Sat, 08 Jul 2006 16:16:25 +0200, Arjan van de Ven a écrit :

> 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()
Yes from the name I would expect they remove the entry from the list...


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC/PATCH] Introduce list_get() and list_get_tail()
  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 18:31 ` Arnd Bergmann
  1 sibling, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2006-07-08 18:31 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-kernel, Andrew Morton

Am Saturday 08 July 2006 07:24 schrieb Dmitry Torokhov:
> +/**
> + * 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;
> +}

I would expect it to be more useful when combined with list_entry(),
something like

#define list_first_entry(list, type, member) \
	container_of((list)->next, type, member)
#define list_last_entry(list, type, member) \
	container_of((list)->prev, type, member)

	Arnd <><

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC/PATCH] Introduce list_get() and list_get_tail()
  2006-07-08 14:16   ` Arjan van de Ven
  2006-07-08 17:02     ` Matthieu CASTET
@ 2006-07-09  3:28     ` Dmitry Torokhov
  2006-07-11 17:43       ` Josef Sipek
  1 sibling, 1 reply; 8+ messages in thread
From: Dmitry Torokhov @ 2006-07-09  3:28 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Andi Kleen, Andrew Morton, linux-kernel, Arnd Bergmann

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC/PATCH] Introduce list_get() and list_get_tail()
  2006-07-09  3:28     ` Dmitry Torokhov
@ 2006-07-11 17:43       ` Josef Sipek
  2006-07-11 17:58         ` Dmitry Torokhov
  0 siblings, 1 reply; 8+ messages in thread
From: Josef Sipek @ 2006-07-11 17:43 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Arjan van de Ven, Andi Kleen, Andrew Morton, linux-kernel,
	Arnd Bergmann

On Sat, Jul 08, 2006 at 11:28:47PM -0400, Dmitry Torokhov wrote:
...
> +#define list_next_entry list_first_entry

list_next_entry, that sounds almost as something which given any list_head
will give you the next entry. That's all fine until you give it the last
list_head in the list - you'll try to use list_entry on a list_head that's
not part of a struct but is the head of the list instead.

> +#define list_prev_entry list_last_entry

Ditto.

Jeff.

-- 
Note 96.3% of all statistics are fiction.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC/PATCH] Introduce list_get() and list_get_tail()
  2006-07-11 17:43       ` Josef Sipek
@ 2006-07-11 17:58         ` Dmitry Torokhov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Torokhov @ 2006-07-11 17:58 UTC (permalink / raw)
  To: Josef Sipek
  Cc: Arjan van de Ven, Andi Kleen, Andrew Morton, linux-kernel,
	Arnd Bergmann

On 7/11/06, Josef Sipek <jsipek@fsl.cs.sunysb.edu> wrote:
> On Sat, Jul 08, 2006 at 11:28:47PM -0400, Dmitry Torokhov wrote:
> ...
> > +#define list_next_entry list_first_entry
>
> list_next_entry, that sounds almost as something which given any list_head
> will give you the next entry. That's all fine until you give it the last
> list_head in the list - you'll try to use list_entry on a list_head that's
> not part of a struct but is the head of the list instead.
>
> > +#define list_prev_entry list_last_entry
>
> Ditto.

The same could be said about regular list_entry(), however we do have
it and it is pretty useful.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-07-11 17:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2006-07-11 17:43       ` Josef Sipek
2006-07-11 17:58         ` Dmitry Torokhov
2006-07-08 18:31 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox