[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC] potential risk for macro QTAILQ_INSERT_BEFORE

From: Wayne Xia
Subject: [Qemu-devel] [RFC] potential risk for macro QTAILQ_INSERT_BEFORE
Date: Wed, 28 Sep 2011 11:38:09 +0800
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv: Gecko/20110902 Thunderbird/3.1.14

    Hi, during my coding, I found macro a bit different from other
QTAIL macros.

QTAILQ_INSERT_AFTER was defined as:
#define QTAILQ_INSERT_AFTER(head, listelm, elm, field) do {             \
        if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
                (elm)->field.tqe_next->field.tqe_prev =                 \
                    &(elm)->field.tqe_next;                             \
        else                                                            \
                (head)->tqh_last = &(elm)->field.tqe_next;              \
        (listelm)->field.tqe_next = (elm);                              \
        (elm)->field.tqe_prev = &(listelm)->field.tqe_next;             \
} while (/*CONSTCOND*/0)
 QTAILQ_INSERT_BEFORE is defined as following:

#define QTAILQ_INSERT_BEFORE(listelm, elm, field) do {
        (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
        (elm)->field.tqe_next = (listelm);                              \
        *(listelm)->field.tqe_prev = (elm);                             \
        (listelm)->field.tqe_prev = &(elm)->field.tqe_next;             \
} while (/*CONSTCOND*/0)

    It did not take care of "head" as QTAILQ_INSERT_AFTER did, so I am
wondering what would happen if I use QTAILQ_INSERT_BEFORE to insert one
element to a queue that have only one element in it, would it happen
that the queue head pointer is not updated and the real first element
is lost? Currently some codes in qemu have used this macro.

Best Regards

Wayne Xia

reply via email to

[Prev in Thread] Current Thread [Next in Thread]