public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org
Subject: [PATCH 1/2] list: unify hlist_add functions
Date: Mon, 16 Mar 2009 00:23:37 +0900	[thread overview]
Message-ID: <20090315152336.GA29167@localhost.localdomain> (raw)

Unify hlist_add_head(), hlist_add_before(), and hlist_add_after().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 include/linux/list.h |   33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

Index: 2.6/include/linux/list.h
===================================================================
--- 2.6.orig/include/linux/list.h
+++ 2.6/include/linux/list.h
@@ -588,35 +588,36 @@ static inline void hlist_del_init(struct
 	}
 }
 
+/*
+ * This is only for internal hlist manipulation where we know
+ * the pprev/next entries already!
+ */
+static inline void __hlist_add(struct hlist_node *new,
+			struct hlist_node **pprev, struct hlist_node *next)
+{
+	new->next = next;
+	if (next)
+		next->pprev = &new->next;
+	*pprev = new;
+	new->pprev = pprev;
+}
+
 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
 {
-	struct hlist_node *first = h->first;
-	n->next = first;
-	if (first)
-		first->pprev = &n->next;
-	h->first = n;
-	n->pprev = &h->first;
+	__hlist_add(n, &h->first, h->first);
 }
 
 /* next must be != NULL */
 static inline void hlist_add_before(struct hlist_node *n,
 					struct hlist_node *next)
 {
-	n->pprev = next->pprev;
-	n->next = next;
-	next->pprev = &n->next;
-	*(n->pprev) = n;
+	__hlist_add(n, next->pprev, next);
 }
 
 static inline void hlist_add_after(struct hlist_node *n,
 					struct hlist_node *next)
 {
-	next->next = n->next;
-	n->next = next;
-	next->pprev = &n->next;
-
-	if(next->next)
-		next->next->pprev  = &next->next;
+	__hlist_add(next, &n->next, n->next);
 }
 
 /*

             reply	other threads:[~2009-03-15 15:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-15 15:23 Akinobu Mita [this message]
2009-03-15 15:25 ` [PATCH 2/2] list: DEBUG_LIST for hlist Akinobu Mita

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=20090315152336.GA29167@localhost.localdomain \
    --to=akinobu.mita@gmail.com \
    --cc=akpm@linux-foundation.org \
    --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