cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] introduce list_get_first/last (Was: [PATCH 3/6] gfs2: simplify	current_tail() via list_last_entry_or_null())
Date: Fri, 15 Nov 2013 18:12:59 +0100	[thread overview]
Message-ID: <20131115171259.GA10687@redhat.com> (raw)
In-Reply-To: <20131115163957.GA28467@redhat.com>

On 11/15, Oleg Nesterov wrote:
>
> But probably list_last_entry() makes sense in the "else" branch,
> athough this is minor.
>
>
> Off-topic. Not sure this really makes sense, but I was thinking about
>
> 	list_get_first(pos, head, member)	\
> 		((pos) = list_first_entry(head, typeof(*pos), member))
>
> and list_get_first() last of course. The obvious advantage is that
> compared to
>
> 	tr = list_last_entry(sdp->sd_ail1_list, struct gfs2_trans, tr_list);
>
> above you do not need to type "struct gfs2_trans",
>
> 	list_get_last(tr, sdp->sd_ail1_list, tr_list);
>
> looks a bit better.

And list.h can use it too.

So how about the patch below? I can't decide whether it cleanups or
uglfies the code, I do not trust my taste ;) But to me it looks a
bit better this way.

Oleg.
--

diff --git a/include/linux/list.h b/include/linux/list.h
index ef95941..f52aba8 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -372,6 +372,12 @@ static inline void list_splice_tail_init(struct list_head *list,
 #define list_last_entry(ptr, type, member) \
 	list_entry((ptr)->prev, type, member)
 
+#define list_get_first(pos, head, member)	\
+	((pos) = list_first_entry(head, typeof(*(pos)), member))
+
+#define list_get_last(pos, head, member)	\
+	((pos) = list_last_entry(head, typeof(*(pos)), member))
+
 /**
  * list_first_entry_or_null - get the first element from a list
  * @ptr:	the list head to take the element from.
@@ -443,7 +449,7 @@ static inline void list_splice_tail_init(struct list_head *list,
  * @member:	the name of the list_struct within the struct.
  */
 #define list_for_each_entry(pos, head, member)				\
-	for (pos = list_first_entry(head, typeof(*pos), member);	\
+	for (list_get_first(pos, head, member);				\
 	     &pos->member != (head);					\
 	     pos = list_next_entry(pos, member))
 
@@ -454,7 +460,7 @@ static inline void list_splice_tail_init(struct list_head *list,
  * @member:	the name of the list_struct within the struct.
  */
 #define list_for_each_entry_reverse(pos, head, member)			\
-	for (pos = list_last_entry(head, typeof(*pos), member);		\
+	for (list_get_last(pos, head, member);				\
 	     &pos->member != (head); 					\
 	     pos = list_prev_entry(pos, member))
 
@@ -517,7 +523,7 @@ static inline void list_splice_tail_init(struct list_head *list,
  * @member:	the name of the list_struct within the struct.
  */
 #define list_for_each_entry_safe(pos, n, head, member)			\
-	for (pos = list_first_entry(head, typeof(*pos), member),	\
+	for (list_get_first(pos, head, member),				\
 		n = list_next_entry(pos, member);			\
 	     &pos->member != (head); 					\
 	     pos = n, n = list_next_entry(n, member))
@@ -564,7 +570,7 @@ static inline void list_splice_tail_init(struct list_head *list,
  * of list entry.
  */
 #define list_for_each_entry_safe_reverse(pos, n, head, member)		\
-	for (pos = list_last_entry(head, typeof(*pos), member),		\
+	for (list_get_last(pos, head, member),				\
 		n = list_prev_entry(pos, member);			\
 	     &pos->member != (head); 					\
 	     pos = n, n = list_prev_entry(n, member))



  reply	other threads:[~2013-11-15 17:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-15  4:32 [Cluster-devel] [PATCH 3/6] gfs2: simplify current_tail() via list_last_entry_or_null() Jeff Liu
2013-11-15 16:39 ` Oleg Nesterov
2013-11-15 17:12   ` Oleg Nesterov [this message]
2013-11-18  5:41     ` [Cluster-devel] introduce list_get_first/last (Was: [PATCH 3/6] gfs2: simplify current_tail() via list_last_entry_or_null()) Jeff Liu

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=20131115171259.GA10687@redhat.com \
    --to=oleg@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).