From: chenqiwu <qiwuchen55@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: akpm@linux-foundation.org, walken@google.com,
rfontana@redhat.com, dbueso@suse.de, tglx@linutronix.de,
linux-kernel@vger.kernel.org, chenqiwu <chenqiwu@xiaomi.com>
Subject: Re: [PATCH] rbtree: introduce three helpers about sort-order iteration
Date: Tue, 10 Mar 2020 10:02:07 +0800 [thread overview]
Message-ID: <20200310020206.GA8961@cqw-OptiPlex-7050> (raw)
In-Reply-To: <20200309165511.GK12561@hirez.programming.kicks-ass.net>
On Mon, Mar 09, 2020 at 05:55:11PM +0100, Peter Zijlstra wrote:
> On Tue, Mar 10, 2020 at 12:02:14AM +0800, qiwuchen55@gmail.com wrote:
> > +/**
> > + * rbtree_for_each_entry_safe - iterate in sort-order over of given type
> > + * allowing the backing memory of @pos to be invalidated.
> > + * @pos: the 'type *' to use as a loop cursor.
> > + * @n: another 'type *' to use as temporary storage.
> > + * @root: 'rb_root *' of the rbtree.
> > + * @field: the name of the rb_node field within 'type'.
> > + *
> > + * rbtree_order_for_each_entry_safe() provides a similar guarantee as
> > + * list_for_each_entry_safe() and allows the sort-order iteration to
> > + * continue independent of changes to @pos by the body of the loop.
> > + *
> > + * Note, however, that it cannot handle other modifications that re-order the
> > + * rbtree it is iterating over. This includes calling rb_erase() on @pos, as
> > + * rb_erase() may rebalance the tree, causing us to miss some nodes.
> > + */
> > +#define rbtree_for_each_entry_safe(pos, n, root, field) \
> > + for (pos = rb_entry_safe(rb_first(root), typeof(*pos), field); \
> > + pos && ({ n = rb_entry_safe(rb_next(&pos->field), \
> > + typeof(*pos), field); 1; }); \
> > + pos = n)
>
> Since this cannot deal with rb_erase(), what exactly is the purpose of
> this thing?
It's just a copy of rbtree_postorder_for_each_entry_safe() for
the usage scenario of sort-order iteration. It can be used for
walking the tree and free all entries of the given type.
prev parent reply other threads:[~2020-03-10 2:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-09 16:02 qiwuchen55
2020-03-09 16:55 ` Peter Zijlstra
2020-03-10 2:02 ` chenqiwu [this message]
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=20200310020206.GA8961@cqw-OptiPlex-7050 \
--to=qiwuchen55@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chenqiwu@xiaomi.com \
--cc=dbueso@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rfontana@redhat.com \
--cc=tglx@linutronix.de \
--cc=walken@google.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®