mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH -mm] [2/3] add list_merge to list.h
@ 2006-08-04  2:15 Nate Diller
  2006-08-04  5:22 ` Andrew Morton
  2006-08-04 18:03 ` Ben Pfaff
  0 siblings, 2 replies; 4+ messages in thread
From: Nate Diller @ 2006-08-04  2:15 UTC (permalink / raw)
  To: Andrew Morton, Jens Axboe; +Cc: Linux Kernel Mailing List

list_merge behaves like list_splice, except it can be used with
headless lists.  that is, the resulting list will have @head
immediately preceeding @list.

This is used by the contig list feature in the Elevator I/O scheduler

Signed-off-by: Nate Diller <nate.diller@gmail.com>

---
 list.h |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
---

diff -urpN -X dontdiff linux-2.6.18-rc1-mm2/include/linux/list.h
linux-dput/include/linux/list.h
--- linux-2.6.18-rc1-mm2/include/linux/list.h	2006-07-18
15:00:53.000000000 -0700
+++ linux-dput/include/linux/list.h	2006-08-03 18:42:00.000000000 -0700
@@ -357,6 +357,27 @@ static inline void list_splice_init(stru
 	}
 }

+/**
+ * list_merge - merge two headless lists
+ * @list: the new list to merge.
+ * @head: the place to add it in the first list.
+ *
+ * This is similar to list_splice(), except it merges every item onto @list,
+ * not excluding @head itself.  It is a noop if @head already immediately
+ * preceeds @list.
+ */
+static inline void list_merge(struct list_head *list, struct list_head *head)
+{
+	struct list_head *last = list->prev;
+	struct list_head *at = head->next;
+
+	list->prev = head;
+	head->next = list;
+
+	last->next = at;
+	at->prev = last;
+}
+
 /**
  * list_entry - get the struct for this entry
  * @ptr:	the &struct list_head pointer.

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

* Re: [PATCH -mm] [2/3] add list_merge to list.h
  2006-08-04  2:15 [PATCH -mm] [2/3] add list_merge to list.h Nate Diller
@ 2006-08-04  5:22 ` Andrew Morton
  2006-08-07 21:37   ` Steven Rostedt
  2006-08-04 18:03 ` Ben Pfaff
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2006-08-04  5:22 UTC (permalink / raw)
  To: Nate Diller; +Cc: axboe, linux-kernel

On Thu, 3 Aug 2006 19:15:15 -0700
"Nate Diller" <nate.diller@gmail.com> wrote:

> +/**
> + * list_merge - merge two headless lists
> + * @list: the new list to merge.
> + * @head: the place to add it in the first list.
> + *
> + * This is similar to list_splice(), except it merges every item onto @list,
> + * not excluding @head itself.  It is a noop if @head already immediately
> + * preceeds @list.

"precedes"

> + */
> +static inline void list_merge(struct list_head *list, struct list_head *head)
> +{
> +	struct list_head *last = list->prev;
> +	struct list_head *at = head->next;
> +
> +	list->prev = head;
> +	head->next = list;
> +
> +	last->next = at;
> +	at->prev = last;
> +}

Interesting.  I didn't realise that none of the existing functions could do
this.  I wonder if we can flesh the comment out a bit: define "headless" a
little more verbosely.

Should we call it list_splice_headless() or something?  list_merge is a bit
vague.


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

* Re: [PATCH -mm] [2/3] add list_merge to list.h
  2006-08-04  2:15 [PATCH -mm] [2/3] add list_merge to list.h Nate Diller
  2006-08-04  5:22 ` Andrew Morton
@ 2006-08-04 18:03 ` Ben Pfaff
  1 sibling, 0 replies; 4+ messages in thread
From: Ben Pfaff @ 2006-08-04 18:03 UTC (permalink / raw)
  To: linux-kernel

"Nate Diller" <nate.diller@gmail.com> writes:

> + * This is similar to list_splice(), except it merges every item onto @list,
> + * not excluding @head itself.  It is a noop if @head already immediately
> + * preceeds @list.

"not excluding"?  Is that the same as "including"?
-- 
Ben Pfaff 
email: blp@cs.stanford.edu
web: http://benpfaff.org


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

* Re: [PATCH -mm] [2/3] add list_merge to list.h
  2006-08-04  5:22 ` Andrew Morton
@ 2006-08-07 21:37   ` Steven Rostedt
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2006-08-07 21:37 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Nate Diller, axboe, linux-kernel


On Thu, 3 Aug 2006, Andrew Morton wrote:

> On Thu, 3 Aug 2006 19:15:15 -0700
> "Nate Diller" <nate.diller@gmail.com> wrote:
>
> > +/**
> > + * list_merge - merge two headless lists
> > + * @list: the new list to merge.
> > + * @head: the place to add it in the first list.
> > + *
> > + * This is similar to list_splice(), except it merges every item onto @list,
> > + * not excluding @head itself.  It is a noop if @head already immediately
> > + * preceeds @list.
>
> "precedes"
>
> > + */
> > +static inline void list_merge(struct list_head *list, struct list_head *head)
> > +{
> > +	struct list_head *last = list->prev;
> > +	struct list_head *at = head->next;
> > +
> > +	list->prev = head;
> > +	head->next = list;
> > +
> > +	last->next = at;
> > +	at->prev = last;
> > +}
>
> Interesting.  I didn't realise that none of the existing functions could do
> this.  I wonder if we can flesh the comment out a bit: define "headless" a
> little more verbosely.
>
> Should we call it list_splice_headless() or something?  list_merge is a bit
> vague.
>

Yes, please do explicitly mention headless.  I could see someone using
this for something with a head and causing some strange bugs.

Also, it might be a good idea to get rid of the "head" in the parameter.
Perhaps call it "start" or something else.  It's a little confusing to
have a headless list operation that calls the start of a list "head".

-- Steve


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

end of thread, other threads:[~2006-08-07 21:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-04  2:15 [PATCH -mm] [2/3] add list_merge to list.h Nate Diller
2006-08-04  5:22 ` Andrew Morton
2006-08-07 21:37   ` Steven Rostedt
2006-08-04 18:03 ` Ben Pfaff

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

Powered by JetHome