From: "Mark Peloquin" <peloquin@us.ibm.com>
To: torvalds@transmeta.com
Cc: linux-kernel@vger.kernel.org, evms-devel@lists.sourceforge.net
Subject: [PATCH] add safe version of list_for_each_entry() to list.h
Date: Thu, 3 Oct 2002 18:42:09 -0500 [thread overview]
Message-ID: <OF9EDF8472.CDE2D9D8-ON85256C47.0080772B@pok.ibm.com> (raw)
Please consider adding the following patch to list.h.
The following patch adds list_for_each_entry_safe() and
list_member() to list.h.
- List_for_each_entry_safe adds a removal-safe version of this macro.
- List_member indicates if the container object is currently in a list.
Thanks.
Mark
diff -Naur old/include/linux/list.h new/include/linux/list.h
--- old/include/linux/list.h Thu Oct 3 18:06:42 2002
+++ new/include/linux/list.h Thu Oct 3 18:10:46 2002
@@ -137,6 +137,15 @@
return head->next == head;
}
+/**
+ * list_member - tests whether a list member is currently on a list
+ * @member: member to evaulate
+ */
+static inline int list_member(struct list_head *member)
+{
+ return ((!member->next || !member->prev) ? 0 : 1);
+}
+
static inline void __list_splice(struct list_head *list,
struct list_head *head)
{
@@ -241,6 +250,20 @@
pos = list_entry(pos->member.next, typeof(*pos), member), \
prefetch(pos->member.next))
+/**
+ * list_for_each_entry_safe - iterate over list safe against removal of list entry
+ * @pos: the type * to use as a loop counter.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = list_entry((head)->next, typeof(*pos), member), \
+ n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, \
+ n = list_entry(pos->member.next, typeof(*pos), member))
+
#endif /* __KERNEL__ || _LVM_H_INCLUDE */
#endif
next reply other threads:[~2002-10-03 23:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-03 23:42 Mark Peloquin [this message]
2002-10-03 23:44 ` [PATCH] add safe version of list_for_each_entry() to list.h Greg KH
2002-10-04 0:25 ` Kevin Corry
2002-10-04 13:58 ` Christoph Hellwig
2002-10-04 13:48 ` Kevin Corry
2002-10-04 13:51 ` Kevin Corry
2002-10-04 15:05 Matthew Wilcox
2002-10-04 15:48 Mark Peloquin
2002-10-04 16:00 ` Matthew Wilcox
2002-10-04 16:33 ` Andrew Morton
2002-10-04 16:40 Mark Peloquin
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=OF9EDF8472.CDE2D9D8-ON85256C47.0080772B@pok.ibm.com \
--to=peloquin@us.ibm.com \
--cc=evms-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.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).