diff mbox

[v6,2/6] queue: Add macro for incremental traversal

Message ID 149727924253.28532.2681638904562623104.stgit@frigg.lan (mailing list archive)
State New, archived
Headers show

Commit Message

Lluís Vilanova June 12, 2017, 2:54 p.m. UTC
Adds macro QTAILQ_FOREACH_CONTINUE to support incremental list
traversal.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 include/qemu/queue.h |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Richard Henderson June 19, 2017, 11:20 p.m. UTC | #1
On 06/12/2017 07:54 AM, Lluís Vilanova wrote:
> Adds macro QTAILQ_FOREACH_CONTINUE to support incremental list
> traversal.
> 
> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
> ---
>   include/qemu/queue.h |   12 ++++++++++++
>   1 file changed, 12 insertions(+)
> 
> diff --git a/include/qemu/queue.h b/include/qemu/queue.h
> index 35292c3155..eb2bf9cb1c 100644
> --- a/include/qemu/queue.h
> +++ b/include/qemu/queue.h
> @@ -415,6 +415,18 @@ struct {                                                                \
>                   (var);                                                  \
>                   (var) = ((var)->field.tqe_next))
>   
> +/**
> + * QTAILQ_FOREACH_CONTINUE:
> + * @var: Variable to resume iteration from.
> + * @field: Field in @var holding a QTAILQ_ENTRY for this queue.
> + *
> + * Resumes iteration on a queue from the element in @var.
> + */
> +#define QTAILQ_FOREACH_CONTINUE(var, field)                             \
> +        for ((var) = ((var)->field.tqe_next);                           \
> +                (var);                                                  \
> +                (var) = ((var)->field.tqe_next))
> +
>   #define QTAILQ_FOREACH_SAFE(var, head, field, next_var)                 \
>           for ((var) = ((head)->tqh_first);                               \
>                   (var) && ((next_var) = ((var)->field.tqe_next), 1);     \
> 
> 

I still say this isn't required if the breakpoint loop is better structured.


r~
Lluís Vilanova June 26, 2017, 12:33 p.m. UTC | #2
Richard Henderson writes:

> On 06/12/2017 07:54 AM, Lluís Vilanova wrote:
>> Adds macro QTAILQ_FOREACH_CONTINUE to support incremental list
>> traversal.
>> 
>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>> ---
>> include/qemu/queue.h |   12 ++++++++++++
>> 1 file changed, 12 insertions(+)
>> 
>> diff --git a/include/qemu/queue.h b/include/qemu/queue.h
>> index 35292c3155..eb2bf9cb1c 100644
>> --- a/include/qemu/queue.h
>> +++ b/include/qemu/queue.h
>> @@ -415,6 +415,18 @@ struct {                                                                \
>> (var);                                                  \
>> (var) = ((var)->field.tqe_next))
>> +/**
>> + * QTAILQ_FOREACH_CONTINUE:
>> + * @var: Variable to resume iteration from.
>> + * @field: Field in @var holding a QTAILQ_ENTRY for this queue.
>> + *
>> + * Resumes iteration on a queue from the element in @var.
>> + */
>> +#define QTAILQ_FOREACH_CONTINUE(var, field)                             \
>> +        for ((var) = ((var)->field.tqe_next);                           \
>> +                (var);                                                  \
>> +                (var) = ((var)->field.tqe_next))
>> +
>> #define QTAILQ_FOREACH_SAFE(var, head, field, next_var)                 \
>> for ((var) = ((head)->tqh_first);                               \
>> (var) && ((next_var) = ((var)->field.tqe_next), 1);     \
>> 
>> 

> I still say this isn't required if the breakpoint loop is better structured.

I can embed the use of QTAILQ into translate-block.c, but I wanted to keep the
implementation of breakpoint lists hidden behind the cpu_breakpoint API.


Thanks,
  Lluis
Richard Henderson June 27, 2017, 1:10 a.m. UTC | #3
On 06/26/2017 05:33 AM, Lluís Vilanova wrote:
> Richard Henderson writes:
> 
>> On 06/12/2017 07:54 AM, Lluís Vilanova wrote:
>>> Adds macro QTAILQ_FOREACH_CONTINUE to support incremental list
>>> traversal.
>>>
>>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>>> ---
>>> include/qemu/queue.h |   12 ++++++++++++
>>> 1 file changed, 12 insertions(+)
>>>
>>> diff --git a/include/qemu/queue.h b/include/qemu/queue.h
>>> index 35292c3155..eb2bf9cb1c 100644
>>> --- a/include/qemu/queue.h
>>> +++ b/include/qemu/queue.h
>>> @@ -415,6 +415,18 @@ struct {                                                                \
>>> (var);                                                  \
>>> (var) = ((var)->field.tqe_next))
>>> +/**
>>> + * QTAILQ_FOREACH_CONTINUE:
>>> + * @var: Variable to resume iteration from.
>>> + * @field: Field in @var holding a QTAILQ_ENTRY for this queue.
>>> + *
>>> + * Resumes iteration on a queue from the element in @var.
>>> + */
>>> +#define QTAILQ_FOREACH_CONTINUE(var, field)                             \
>>> +        for ((var) = ((var)->field.tqe_next);                           \
>>> +                (var);                                                  \
>>> +                (var) = ((var)->field.tqe_next))
>>> +
>>> #define QTAILQ_FOREACH_SAFE(var, head, field, next_var)                 \
>>> for ((var) = ((head)->tqh_first);                               \
>>> (var) && ((next_var) = ((var)->field.tqe_next), 1);     \
>>>
>>>
> 
>> I still say this isn't required if the breakpoint loop is better structured.
> 
> I can embed the use of QTAILQ into translate-block.c, but I wanted to keep the
> implementation of breakpoint lists hidden behind the cpu_breakpoint API.

I think using QTAILQ in the common main loop is better than twisting the logic 
so that the loop is unnaturally split into a subroutine.


r~
Lluís Vilanova June 27, 2017, 9:13 a.m. UTC | #4
Richard Henderson writes:

> On 06/26/2017 05:33 AM, Lluís Vilanova wrote:
>> Richard Henderson writes:
>> 
>>> On 06/12/2017 07:54 AM, Lluís Vilanova wrote:
>>>> Adds macro QTAILQ_FOREACH_CONTINUE to support incremental list
>>>> traversal.
>>>> 
>>>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>>>> ---
>>>> include/qemu/queue.h |   12 ++++++++++++
>>>> 1 file changed, 12 insertions(+)
>>>> 
>>>> diff --git a/include/qemu/queue.h b/include/qemu/queue.h
>>>> index 35292c3155..eb2bf9cb1c 100644
>>>> --- a/include/qemu/queue.h
>>>> +++ b/include/qemu/queue.h
>>>> @@ -415,6 +415,18 @@ struct {                                                                \
>>>> (var);                                                  \
>>>> (var) = ((var)->field.tqe_next))
>>>> +/**
>>>> + * QTAILQ_FOREACH_CONTINUE:
>>>> + * @var: Variable to resume iteration from.
>>>> + * @field: Field in @var holding a QTAILQ_ENTRY for this queue.
>>>> + *
>>>> + * Resumes iteration on a queue from the element in @var.
>>>> + */
>>>> +#define QTAILQ_FOREACH_CONTINUE(var, field)                             \
>>>> +        for ((var) = ((var)->field.tqe_next);                           \
>>>> +                (var);                                                  \
>>>> +                (var) = ((var)->field.tqe_next))
>>>> +
>>>> #define QTAILQ_FOREACH_SAFE(var, head, field, next_var)                 \
>>>> for ((var) = ((head)->tqh_first);                               \
>>>> (var) && ((next_var) = ((var)->field.tqe_next), 1);     \
>>>> 
>>>> 
>> 
>>> I still say this isn't required if the breakpoint loop is better structured.
>> 
>> I can embed the use of QTAILQ into translate-block.c, but I wanted to keep the
>> implementation of breakpoint lists hidden behind the cpu_breakpoint API.

> I think using QTAILQ in the common main loop is better than twisting the logic
> so that the loop is unnaturally split into a subroutine.

Ok, then I'll integrate that into the new series.

Thanks,
  Lluis
diff mbox

Patch

diff --git a/include/qemu/queue.h b/include/qemu/queue.h
index 35292c3155..eb2bf9cb1c 100644
--- a/include/qemu/queue.h
+++ b/include/qemu/queue.h
@@ -415,6 +415,18 @@  struct {                                                                \
                 (var);                                                  \
                 (var) = ((var)->field.tqe_next))
 
+/**
+ * QTAILQ_FOREACH_CONTINUE:
+ * @var: Variable to resume iteration from.
+ * @field: Field in @var holding a QTAILQ_ENTRY for this queue.
+ *
+ * Resumes iteration on a queue from the element in @var.
+ */
+#define QTAILQ_FOREACH_CONTINUE(var, field)                             \
+        for ((var) = ((var)->field.tqe_next);                           \
+                (var);                                                  \
+                (var) = ((var)->field.tqe_next))
+
 #define QTAILQ_FOREACH_SAFE(var, head, field, next_var)                 \
         for ((var) = ((head)->tqh_first);                               \
                 (var) && ((next_var) = ((var)->field.tqe_next), 1);     \