[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-ppc] [QEMU PATCH v6 2/2] migration: migrate QTAILQ
From: |
Jianjun Duan |
Subject: |
Re: [Qemu-ppc] [QEMU PATCH v6 2/2] migration: migrate QTAILQ |
Date: |
Fri, 14 Oct 2016 09:43:19 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 |
I need to double check my code. My build passed and migration test also
succeeded.
On 10/14/2016 04:07 AM, Paolo Bonzini wrote:
>
>
> On 14/10/2016 12:44, Dr. David Alan Gilbert wrote:
>>>> +#define QTAILQ_RAW_INSERT_TAIL(head, elm, entry) do {
>>>> \
>>>> + *((void **) ((char *) (elm) + (entry) + QTAILQ_NEXT_OFFSET)) =
>>>> NULL; \
>>>> + *((void **) ((char *) (elm) + (entry) + QTAILQ_PREV_OFFSET)) =
>>>> \
>>>> + *((void **) ((char *) (head) + QTAILQ_LAST_OFFSET));
>>>> \
>>>> + **((void ***)((char *) (head) + QTAILQ_LAST_OFFSET)) = (elm);
>>>> \
>>>> + *((void **) ((char *) (head) + QTAILQ_LAST_OFFSET)) =
>>>> \
>>>> + (void *) ((char *) (elm) + (entry) + QTAILQ_NEXT_OFFSET);
>>>> \
>>>> +} while (/*CONSTCOND*/0)
>> I wonder if there's a simpler way to do this; I'm not sure this works, but
>> something like:
>>
>> struct QTAILQDummy {
>> char dummy;
>> };
>>
>> QTAILQ_HEAD(QTAILQRawHead, struct QTAILQDummy)
>> typedef QTAILQ_ENTRY(struct QTAILQDummy) QTAILQRawEntry;
>>
>> #define QTAILQ_RAW_FOREACH(elm, head, entry)
>> \
>> for ((elm) = ((struct QTAILQRawHead *)head)->tqh_first)
>> \
>> (elm);
>> \
>> (elm) =
>> \
>> (elm) = ((QTAILQRawEntry *)((char *) (elm) + (entry)))->tqh_next
>>
>> and then I think elm gets declared as a struct QTAILQDummy.
>> But it does avoid those FIRST_OFFSET/LAST_OFFSET/NEXT_OFFSET/PREV_OFFSET
>> calculations.
>
> 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.
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