You are right. Thanks.
在 2016年3月29日星期二 UTC+8下午12:51:35,Xy Wang写道:
>
> QUEUE_ADD(h, n) append n to h, after QUEUE_ADDing, h is a valid queue
> head, but n is not a valid queue and is not iteratable
>
> On Thursday, March 24, 2016 at 10:30:06 AM UTC+8, Xiaomao Lan wrote:
>>
>> Is QUEUE_ADD(h, n) to add n to h, rather than to add h to n ?
>>
>>
>>
>> 在 2016年3月23日星期三 UTC+8下午7:00:43,Xiaomao Lan写道:
>>>
>>>
>>>
>>> Modify the code: modify macro QUEUE_ADD, and not to traverse wq, then it
>>> is ok.
>>>
>>>
>>> #define QUEUE_NEXT_NEXT(q) (QUEUE_NEXT(QUEUE_NEXT(q)))
>>>
>>> Modify:
>>> #define QUEUE_ADD(h, n)
>>> \
>>> do {
>>> \
>>> QUEUE_PREV_NEXT(h) = QUEUE_NEXT(n);
>>> \
>>> QUEUE_NEXT_PREV(n) = QUEUE_PREV(h);
>>> \
>>> QUEUE_PREV(h) = QUEUE_PREV(n);
>>> \
>>> QUEUE_PREV_NEXT(h) = (h);
>>> \
>>> }
>>> \
>>> while (0)
>>>
>>> to:
>>> #define QUEUE_ADD(h, n)
>>> \
>>> do {
>>> \
>>> QUEUE_PREV_NEXT(h) = (n);
>>> \
>>> QUEUE_NEXT_PREV(h) = QUEUE_PREV(n);
>>> \
>>> QUEUE_NEXT_NEXT(n) = QUEUE_NEXT(h);
>>> \
>>> QUEUE_PREV(n) = QUEUE_PREV(h);
>>> \
>>> }
>>> \
>>> while (0)
>>>
>>>
>>>
>>> int main()
>>> {
>>> ......
>>>
>>> QUEUE_ADD(&wq, &wq2); // add wq to wq2
>>>
>>> // can not traverse wq, its data pointer wq2.
>>> /* QUEUE_FOREACH(q, &wq)
>>> {
>>> pw = QUEUE_DATA(q, uv__work, wq);
>>> printf("queue wq data is %d.\n", pw->id);
>>> }
>>> */ printf("-----------------------------\n");
>>>
>>>
>>> .....
>>> return 0;
>>> }
>>>
>>>
>>> The program output:
>>> queue wq data is 1.
>>> queue wq data is 2.
>>> queue wq data is 3.
>>> -----------------------------
>>> queue wq2 data is 4.
>>> -----------------------------
>>> -----------------------------
>>> queue wq2 data is 4.
>>> queue wq2 data is 1.
>>> queue wq2 data is 2.
>>> queue wq2 data is 3.
>>> -----------------------------
>>>
>>>
>>>
>>>
>>>
>>>
>>> 在 2016年3月15日星期二 UTC+8上午9:52:46,Xiaomao Lan写道:
>>>>
>>>> QUEUE wq2;
>>>> QUEUE_INIT(&wq2);
>>>>
>>>> In the codes, had written.
>>>>
>>>> 在 2016年3月9日星期三 UTC+8下午3:13:28,Xy Wang写道:
>>>>>
>>>>> after `QUEUE_ADD(&wq, &wq2)`, `wq2` is not iterable and it is not
>>>>> still a valid queue header, all you should do is `QUEUE_INIT(&wq2);`
>>>>>
>>>>> On Tuesday, March 8, 2016 at 6:03:11 PM UTC+8, Xiaomao Lan wrote:
>>>>>>
>>>>>>
>>>>>> The submitted at github:
>>>>>> https://github.com/libuv/libuv/issues/754
>>>>>>
>>>>>> The code is modified, but the issue still exist.
>>>>>> New code: add QUEUE_INIT(&w1.wq); .... QUEUE_INIT(&w4.wq);
>>>>>>
>>>>>>
>>>>>> #include "queue.h"
>>>>>> #include <stdio.h>
>>>>>>
>>>>>> struct uv__work {
>>>>>> int id;
>>>>>> void* wq[2];
>>>>>> };
>>>>>>
>>>>>> #define QUEUE_DATA(ptr, type, field) \
>>>>>> ((type *) ((char *) (ptr) - offsetof(type, field)))
>>>>>>
>>>>>>
>>>>>> static QUEUE wq;
>>>>>>
>>>>>> int main()
>>>>>> {
>>>>>> struct uv__work *pw;
>>>>>> QUEUE* q;
>>>>>>
>>>>>> QUEUE_INIT(&wq);
>>>>>>
>>>>>> struct uv__work w1;
>>>>>> w1.id = 1;
>>>>>> QUEUE_INIT(&w1.wq);
>>>>>> QUEUE_INSERT_TAIL(&wq, &w1.wq);
>>>>>>
>>>>>> struct uv__work w2;
>>>>>> w2.id = 2;
>>>>>> QUEUE_INIT(&w2.wq);
>>>>>> QUEUE_INSERT_TAIL(&wq, &w2.wq);
>>>>>>
>>>>>> struct uv__work w3;
>>>>>> w3.id = 3;
>>>>>> QUEUE_INIT(&w3.wq);
>>>>>> QUEUE_INSERT_TAIL(&wq, &w3.wq);
>>>>>>
>>>>>>
>>>>>> QUEUE_FOREACH(q, &wq)
>>>>>> {
>>>>>> pw = QUEUE_DATA(q, uv__work, wq);
>>>>>> printf("queue wq data is %d.\n", pw->id);
>>>>>> }
>>>>>> printf("-----------------------------\n");
>>>>>>
>>>>>> QUEUE wq2;
>>>>>> QUEUE_INIT(&wq2);
>>>>>>
>>>>>> struct uv__work w4;
>>>>>> w4.id = 4;
>>>>>> QUEUE_INIT(&w4.wq);
>>>>>> QUEUE_INSERT_TAIL(&wq2, &w4.wq);
>>>>>>
>>>>>> QUEUE_FOREACH(q, &wq2)
>>>>>> {
>>>>>> pw = QUEUE_DATA(q, uv__work, wq);
>>>>>> printf("queue wq2 data is %d.\n", pw->id);
>>>>>> }
>>>>>> printf("-----------------------------\n");
>>>>>>
>>>>>>
>>>>>> QUEUE_ADD(&wq, &wq2); // add
>>>>>>
>>>>>> QUEUE_FOREACH(q, &wq)
>>>>>> {
>>>>>> pw = QUEUE_DATA(q, uv__work, wq);
>>>>>> printf("queue wq data is %d.\n", pw->id);
>>>>>> }
>>>>>> printf("-----------------------------\n");
>>>>>>
>>>>>> QUEUE_FOREACH(q, &wq2)
>>>>>> {
>>>>>> pw = QUEUE_DATA(q, uv__work, wq);
>>>>>> printf("queue wq2 data is %d.\n", pw->id);
>>>>>> }
>>>>>> printf("-----------------------------\n");
>>>>>>
>>>>>> return 0;
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
--
You received this message because you are subscribed to the Google Groups
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.