From: Jan Kiszka <jan.kiszka@siemens.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 1/2] Add TAILQ_FOREACH_SAFE
Date: Wed, 19 Nov 2008 16:50:17 +0100 [thread overview]
Message-ID: <492435B9.3010106@siemens.com> (raw)
In-Reply-To: <492429F3.3010202@codemonkey.ws>
Anthony Liguori wrote:
> Jan Kiszka wrote:
>> Add TAILQ iterator that allows to safely remove elements while walking
>> the list.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>
>> sys-queue.h | 6 ++++++
>> 1 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/sys-queue.h b/sys-queue.h
>> index 3d0773e..b92a77f 100644
>> --- a/sys-queue.h
>> +++ b/sys-queue.h
>> @@ -210,6 +210,12 @@ struct
>> { \
>>
>> (var); \
>> (var) = ((var)->field.tqe_next))
>>
>> +#define TAILQ_FOREACH_SAFE(var, head, field,
>> next_var) \
>> + for ((var) =
>> ((head)->tqh_first); \
>> + (var) ? ({ (next_var) = ((var)->field.tqe_next); 1;
>> }) \
>> + :
>> 0; \
>> + (var) = (next_var))
>>
>
> So the Linux implementation of this is:
>
> #define list_for_each_safe(pos, n, head) \
> for (pos = (head)->next, n = pos->next; pos != (head); \
> pos = n, n = pos->next)
This would relate to CIRCLEQ, not TAILQ.
>
> I'd prefer something similar:
>
> #define TAILQ_FOREACH_SAFE(var, head, field, next_var)
> for (var = (head)->tqh_first, next_var = var->field.tqe_next;
> var;
> var = next_var, next_var = var->field.tqe_next)
>
> As it's functionally equivalent and avoids using a GCC-ism ({}).
Won't fly, next_var can become NULL and would be dereferenced without a
prior check. Unless I'm totally blind now, there is no
TAILQ_FOREACH_SAFE without "GCC-ism". But I think I could switch to
CIRCLEQ and add CIRCLEQ_FOREACH_SAFE instead.
Jan
--
Siemens AG, Corporate Technology, CT SE 2 ES-OS
Corporate Competence Center Embedded Linux
next prev parent reply other threads:[~2008-11-19 15:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-19 13:48 [Qemu-devel] [PATCH 0/2] Use TAILQ for breakpoints Jan Kiszka
2008-11-19 13:48 ` [Qemu-devel] [PATCH 2/2] Use sys-queue.h for break/watchpoint managment Jan Kiszka
2008-11-19 15:01 ` Anthony Liguori
2008-11-25 22:14 ` Anthony Liguori
2008-11-19 13:48 ` [Qemu-devel] [PATCH 1/2] Add TAILQ_FOREACH_SAFE Jan Kiszka
2008-11-19 15:00 ` Anthony Liguori
2008-11-19 15:50 ` Jan Kiszka [this message]
2008-11-19 16:48 ` [Qemu-devel] " Anthony Liguori
2008-11-20 13:21 ` Jan Kiszka
2008-11-20 13:27 ` Jamie Lokier
2008-11-24 11:35 ` Jan Kiszka
2008-11-25 22:05 ` Anthony Liguori
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=492435B9.3010106@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).