From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8pk9-0002eT-VL for qemu-devel@nongnu.org; Wed, 28 Sep 2011 04:43:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8pk8-0000sz-Qp for qemu-devel@nongnu.org; Wed, 28 Sep 2011 04:43:53 -0400 Received: from david.siemens.de ([192.35.17.14]:31526) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8pk8-0000lR-FA for qemu-devel@nongnu.org; Wed, 28 Sep 2011 04:43:52 -0400 Message-ID: <4E82DE42.6000708@siemens.com> Date: Wed, 28 Sep 2011 10:43:46 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <4E8296A1.1000407@linux.vnet.ibm.com> In-Reply-To: <4E8296A1.1000407@linux.vnet.ibm.com> Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC] potential risk for macro QTAILQ_INSERT_BEFORE List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wayne Xia Cc: qemu-devel@nongnu.org On 2011-09-28 05:38, Wayne Xia wrote: > 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. The code is fine: a QTAILQ head consists of a dummy entry element that looks for the first element as if a normal element would precede it. In contrast, there is no dummy "end element", the last one just points to NULL. Therefore we need to handle this separately. Jan -- Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux