qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wayne Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel]  [RFC] potential risk for macro QTAILQ_INSERT_BEFORE
Date: Wed, 28 Sep 2011 11:38:09 +0800	[thread overview]
Message-ID: <4E8296A1.1000407@linux.vnet.ibm.com> (raw)

    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
mail:xiawenc@linux.vnet.ibm.com
tel:86-010-82450803

             reply	other threads:[~2011-09-28  3:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-28  3:38 Wayne Xia [this message]
2011-09-28  8:43 ` [Qemu-devel] [RFC] potential risk for macro QTAILQ_INSERT_BEFORE Jan Kiszka
2011-09-29  2:08   ` Wayne Xia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E8296A1.1000407@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).