|
From: | Anthony Liguori |
Subject: | Re: [Qemu-devel] [PATCH 1/2] Add TAILQ_FOREACH_SAFE |
Date: | Wed, 19 Nov 2008 09:00:03 -0600 |
User-agent: | Thunderbird 2.0.0.17 (X11/20080925) |
Jan Kiszka wrote:
Add TAILQ iterator that allows to safely remove elements while walking the list. Signed-off-by: Jan Kiszka <address@hidden> --- 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) 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 ({}). Regards, Anthony Liguori
[Prev in Thread] | Current Thread | [Next in Thread] |