[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-ppc] [Qemu-devel] [QEMU PATCH v6 2/2] migration: migrate QTAIL
From: |
Jianjun Duan |
Subject: |
Re: [Qemu-ppc] [Qemu-devel] [QEMU PATCH v6 2/2] migration: migrate QTAILQ |
Date: |
Fri, 14 Oct 2016 14:10:59 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 |
On 10/14/2016 11:39 AM, Paolo Bonzini wrote:
>
>>> Another possibility is a macro like
>>>
>>> #define field_at_offset(base, offset, type) \
>>> ((type) (((char *) (base)) + (offset)))
>>>
>>> so that you can do
>>>
>>> *field_at_offset(void **, elm, (entry) + QTAILQ_NEXT_OFFSET) = NULL;
>>> *field_at_offset(void ***, elm, (entry) + QTAILQ_PREV_OFFSET) =
>>> *field_at_offset(void ***, head, QTAILQ_LAST_OFFSET);
>>> **field_at_offset(void ***, head, QTAILQ_LAST_OFFSET) = (elm);
>>> *field_at_offset(void ***, head, QTAILQ_LAST_OFFSET) =
>>> field_at_offset(void **, elm, (entry) + QTAILQ_NEXT_OFFSET);
>>
>> The thing is that we don't know type at all. So only the offset values
>> is used. This is intended for QTAILQ of any type.
>
> Sure, my code is identical to yours---just with more macros for readability,
> and a little more type-safe. Another possibility:
>
> #define QTAILQ_RAW_NEXT(elm, entry) \
> (*field_at_offset(void **, elm, (entry) + QTAILQ_NEXT_OFFSET))
> #define QTAILQ_RAW_PREV(elm, entry) \
> (*field_at_offset(void ***, elm, (entry) + QTAILQ_PREV_OFFSET))
> #define QTAILQ_RAW_LAST(head) \
> (*field_at_offset(void ***, head, QTAILQ_LAST_OFFSET))
>
> QTAILQ_RAW_NEXT(elm, entry) = NULL;
> QTAILQ_RAW_PREV(elm, entry) = QTAILQ_RAW_LAST(head);
> *QTAILQ_RAW_LAST(head) = (elm);
> QTAILQ_RAW_LAST(head) = &QTAILQ_RAW_NEXT(elm, entry);
>
You are right. The readability can be approved.
Thanks,
Jianjun
> Thanks,
>
> Paolo
>
>> Thanks,
>> Jianjun
>>
>>>
>>> or something like that (note that I've always used the same type for
>>> next and last, by the way).
>>>
>>> Paolo
>>>
>>
>>
>
- [Qemu-ppc] [QEMU PATCH v6 0/2] migration: migrate QTAILQ, Jianjun Duan, 2016/10/13
- Re: [Qemu-ppc] [QEMU PATCH v6 2/2] migration: migrate QTAILQ, Jianjun Duan, 2016/10/14
- Re: [Qemu-ppc] [QEMU PATCH v6 2/2] migration: migrate QTAILQ, Dr. David Alan Gilbert, 2016/10/14
- Re: [Qemu-ppc] [QEMU PATCH v6 2/2] migration: migrate QTAILQ, Jianjun Duan, 2016/10/14
- Re: [Qemu-ppc] [Qemu-devel] [QEMU PATCH v6 2/2] migration: migrate QTAILQ, Halil Pasic, 2016/10/15
- Re: [Qemu-ppc] [Qemu-devel] [QEMU PATCH v6 2/2] migration: migrate QTAILQ, Jianjun Duan, 2016/10/17
- Re: [Qemu-ppc] [Qemu-devel] [QEMU PATCH v6 2/2] migration: migrate QTAILQ, Dr. David Alan Gilbert, 2016/10/21
- Re: [Qemu-ppc] [Qemu-devel] [QEMU PATCH v6 2/2] migration: migrate QTAILQ, Jianjun Duan, 2016/10/21
Re: [Qemu-ppc] [Qemu-devel] [QEMU PATCH v6 0/2] migration: migrate QTAILQ, no-reply, 2016/10/13