From: Roger Pau Monne <roger.pau@citrix.com>
To: <linux-kernel@vger.kernel.org>
Cc: Roger Pau Monne <roger.pau@citrix.com>,
Huang Ying <ying.huang@intel.com>,
Konrad Rzeszutek Wilk <konrad@kernel.org>
Subject: [PATCH v2 2/3] llist: add a safe version of llist_for_each_entry
Date: Mon, 10 Dec 2012 18:24:49 +0100 [thread overview]
Message-ID: <1355160290-22180-2-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1355160290-22180-1-git-send-email-roger.pau@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Konrad Rzeszutek Wilk <konrad@kernel.org>
---
include/linux/llist.h | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/include/linux/llist.h b/include/linux/llist.h
index a5199f6..f611cd8 100644
--- a/include/linux/llist.h
+++ b/include/linux/llist.h
@@ -125,6 +125,33 @@ static inline void init_llist_head(struct llist_head *list)
(pos) = llist_entry((pos)->member.next, typeof(*(pos)), member))
/**
+ * llist_for_each_entry_safe - safely iterate over some deleted entries of
+ * lock-less list of given type
+ * @pos: the type * to use as a loop cursor.
+ * @n: the &struct llist_node to use as a temporary loop cursor
+ * @node: the fist entry of deleted list entries.
+ * @member: the name of the llist_node with the struct.
+ *
+ * In general, some entries of the lock-less list can be traversed
+ * safely only after being removed from list, so start with an entry
+ * instead of list head.
+ *
+ * If being used on entries deleted from lock-less list directly, the
+ * traverse order is from the newest to the oldest added entry. If
+ * you want to traverse from the oldest to the newest, you must
+ * reverse the order by yourself before traversing.
+ *
+ * n is used to store a reference to the next item llist_node, so
+ * pos can be freed while iterating.
+ */
+#define llist_for_each_entry_safe(pos, n, node, member) \
+ for ((pos) = llist_entry((node), typeof(*(pos)), member), \
+ (n) = (pos)->member.next; \
+ &(pos)->member != NULL; \
+ (pos) = llist_entry(n, typeof(*(pos)), member), \
+ (n) = (&(pos)->member != NULL) ? (pos)->member.next : NULL)
+
+/**
* llist_empty - tests whether a lock-less list is empty
* @head: the list to test
*
--
1.7.7.5 (Apple Git-26)
next prev parent reply other threads:[~2012-12-10 17:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-10 17:24 [PATCH v2 1/3] xen-blkback: implement safe iterator for the list of persistent grants Roger Pau Monne
2012-12-10 17:24 ` Roger Pau Monne [this message]
2012-12-11 0:51 ` [PATCH v2 2/3] llist: add a safe version of llist_for_each_entry Huang Ying
2012-12-11 11:25 ` [PATCH v3] " Roger Pau Monne
2012-12-12 0:37 ` Huang Ying
2012-12-12 9:32 ` Roger Pau Monné
2012-12-10 17:24 ` [PATCH v2 3/3] xen-blkfront: transverse list of persistent grants safely Roger Pau Monne
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=1355160290-22180-2-git-send-email-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=konrad@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ying.huang@intel.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
all inboxes | Powered by JetHome®