From nobody Fri Nov 7 00:45:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544629658380394.8368281462035; Wed, 12 Dec 2018 07:47:38 -0800 (PST) Received: from localhost ([::1]:45683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX6jT-0003UB-QS for importer@patchew.org; Wed, 12 Dec 2018 10:47:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX6Mh-0000zm-8k for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:24:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX6Mb-0000K9-0v for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:23:59 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:38075) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gX6Ma-0000Im-JI for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:23:52 -0500 Received: by mail-wm1-x344.google.com with SMTP id m22so6400441wml.3 for ; Wed, 12 Dec 2018 07:23:52 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id u10sm15878859wrr.33.2018.12.12.07.23.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Dec 2018 07:23:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=g3KPNe2kP2NEI6eLybjxxMRayw6otf40/66Uv29pH04=; b=ZsoZpBIIzyMdgnd2pWQj7wIRWjzyEyypnK64HH5TdFBvx9A3k3P0QMKvzyvTsG2MKI ouI+Xbx+G9Di8oVqslHB9cfHG1ZTCYetf6ZtoACBgmJPqzEGRik2VBcoGvjoZblH5EE1 vLVUkw1Z2V2+wjpa/ZIsHzIQALqIEESL4z8ddF6NDBwEwTIXLR+Y81DzkDcJMBmmUQRB XNZFcREGU0iUxnSVVcLhdJMVv4uOAxyZbUsuGHH+7zSF4Lg3/8lQuGhSNFLy2t7xWsqV /zdRO4O7rCBJWD5S80FJA2D7s2w8tSyev3gyfORrgY8w/n8XVx4VfzZvViMES14fy2H1 8VNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=g3KPNe2kP2NEI6eLybjxxMRayw6otf40/66Uv29pH04=; b=BCEAQ0uIacCs+/2HBbAj5tUfjaLzstG0knE2NmopE33AWswIqfA+v3rU6Qwz+VcdZh 9Obsn434EnBgSCDcs0Xwf447B7PdvTu5e1wfxNsfmemna9zc4jcgIeYG9q+AmTbcboJO 2TviFEkmFhYU+j+ew7awhYx/3/bw09fCaxYJO7N9Dmw/KeRMmIixjJBmUOvw3l1qxHAT b6vF1Z6dr70qjhuP+qGlUDmjPcGUrHhkHZa0f9/07ZvRyzMeGKqlLKdEq9jETcpCCJ5I GTqB0vIKzuNR8CUzbXa/yeA+fyKxZZza8OjvlhfsR729GxD5C3Ae9bzsDrE5heb0ksaL Ai0g== X-Gm-Message-State: AA+aEWb7tPrioFwL6wGP0QNqwgJqyu+V6Piwq/Qr9fAtTGtpq671NaI3 laq7id9AtqyMr5eYCuDzsEBFEHO3 X-Google-Smtp-Source: AFSGD/X6e1A9vLZsIGfB1SPpos30EOPG/jBYNRLaSo1a5EPD5yhzjp+ABSiApqmF3YAE4M6ts7xqcQ== X-Received: by 2002:a1c:58ce:: with SMTP id m197mr7076284wmb.31.1544628230944; Wed, 12 Dec 2018 07:23:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 12 Dec 2018 16:22:51 +0100 Message-Id: <1544628195-37728-31-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1544628195-37728-1-git-send-email-pbonzini@redhat.com> References: <1544628195-37728-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PULL 30/54] qemu/queue.h: reimplement QTAILQ without pointer-to-pointers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" QTAILQ is a doubly linked list, with a pointer-to-pointer to the last element from the head, and the previous element from each node. But if you squint enough, QTAILQ becomes a combination of a singly-linked forwards list, and another singly-linked list which goes backwards and is circular. This is the idea that lets QTAILQ implement reverse iteration: only, because the backwards list points inside the node, accessing the previous element needs to go two steps back and one forwards. What this patch does is implement it in these terms, without actually changing the in-memory layout at all. The coexistence of the two lists is realized by making QTAILQ_HEAD and QTAILQ_ENTRY unions of the forwards pointer and a generic QTailQLink node. Thq QTailQLink can walk the list in both directions; the union is needed so that the forwards pointer can have the correct type, as a sort of poor man's template. While there are other ways to get the same layout without a union, this one has the advantage of simpler operation in the debugger, because the fields tqh_first and tqe_next still exist as before the patch. Those fields are also used by scripts/qemugdb/mtree.py, so it's a good idea to preserve them. The advantage of the new representation is that the two-back-one-forward dance done by backwards accesses can be done all while operating on QTailQLinks. No casting to the head struct is needed anymore because, even though the QTailQLink's forward pointer is a void *, we can use typeof to recover the correct type. This patch only changes the implementation, not the interface. The next patch will remove the head struct name from the backwards visit macros. Signed-off-by: Paolo Bonzini --- include/qemu/queue.h | 139 ++++++++++++++++++++---------------------= ---- include/qemu/rcu_queue.h | 45 ++++++++------- scripts/cocci-macro-file.h | 14 ++--- 3 files changed, 92 insertions(+), 106 deletions(-) diff --git a/include/qemu/queue.h b/include/qemu/queue.h index b9571e9..a893fac 100644 --- a/include/qemu/queue.h +++ b/include/qemu/queue.h @@ -346,23 +346,28 @@ struct { = \ #define QSIMPLEQ_FIRST(head) ((head)->sqh_first) #define QSIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) =20 +typedef struct QTailQLink { + void *tql_next; + struct QTailQLink *tql_prev; +} QTailQLink; =20 /* - * Tail queue definitions. + * Tail queue definitions. The union acts as a poor man template, as if + * it were QTailQLink. */ #define QTAILQ_HEAD(name, type) \ -struct name { \ - type *tqh_first; /* first element */ \ - type **tqh_last; /* addr of last next element */ \ +union name { \ + struct type *tqh_first; /* first element */ \ + QTailQLink tqh_circ; /* link for circular backwards list = */ \ } =20 #define QTAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).tqh_first } + { .tqh_circ =3D { NULL, &(head).tqh_circ } } =20 #define QTAILQ_ENTRY(type) \ -struct { \ - type *tqe_next; /* next element */ \ - type **tqe_prev; /* address of previous next element */ \ +union { \ + struct type *tqe_next; /* next element */ \ + QTailQLink tqe_circ; /* link for circular backwards list = */ \ } =20 /* @@ -370,51 +375,51 @@ struct { = \ */ #define QTAILQ_INIT(head) do { \ (head)->tqh_first =3D NULL; \ - (head)->tqh_last =3D &(head)->tqh_first; \ + (head)->tqh_circ.tql_prev =3D &(head)->tqh_circ; \ } while (/*CONSTCOND*/0) =20 #define QTAILQ_INSERT_HEAD(head, elm, field) do { \ if (((elm)->field.tqe_next =3D (head)->tqh_first) !=3D NULL) = \ - (head)->tqh_first->field.tqe_prev =3D \ - &(elm)->field.tqe_next; \ + (head)->tqh_first->field.tqe_circ.tql_prev =3D \ + &(elm)->field.tqe_circ; \ else \ - (head)->tqh_last =3D &(elm)->field.tqe_next; \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ (head)->tqh_first =3D (elm); \ - (elm)->field.tqe_prev =3D &(head)->tqh_first; \ + (elm)->field.tqe_circ.tql_prev =3D &(head)->tqh_circ; \ } while (/*CONSTCOND*/0) =20 #define QTAILQ_INSERT_TAIL(head, elm, field) do { \ (elm)->field.tqe_next =3D NULL; \ - (elm)->field.tqe_prev =3D (head)->tqh_last; \ - *(head)->tqh_last =3D (elm); \ - (head)->tqh_last =3D &(elm)->field.tqe_next; \ + (elm)->field.tqe_circ.tql_prev =3D (head)->tqh_circ.tql_prev; \ + (head)->tqh_circ.tql_prev->tql_next =3D (elm); \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ } while (/*CONSTCOND*/0) =20 #define QTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ if (((elm)->field.tqe_next =3D (listelm)->field.tqe_next) !=3D NUL= L)\ - (elm)->field.tqe_next->field.tqe_prev =3D \ - &(elm)->field.tqe_next; \ + (elm)->field.tqe_next->field.tqe_circ.tql_prev =3D \ + &(elm)->field.tqe_circ; \ else \ - (head)->tqh_last =3D &(elm)->field.tqe_next; \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ (listelm)->field.tqe_next =3D (elm); \ - (elm)->field.tqe_prev =3D &(listelm)->field.tqe_next; \ + (elm)->field.tqe_circ.tql_prev =3D &(listelm)->field.tqe_circ; \ } while (/*CONSTCOND*/0) =20 -#define QTAILQ_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.tqe_prev =3D (listelm)->field.tqe_prev; \ - (elm)->field.tqe_next =3D (listelm); \ - *(listelm)->field.tqe_prev =3D (elm); \ - (listelm)->field.tqe_prev =3D &(elm)->field.tqe_next; \ +#define QTAILQ_INSERT_BEFORE(listelm, elm, field) do { = \ + (elm)->field.tqe_circ.tql_prev =3D (listelm)->field.tqe_circ.tql_p= rev; \ + (elm)->field.tqe_next =3D (listelm); = \ + (listelm)->field.tqe_circ.tql_prev->tql_next =3D (elm); = \ + (listelm)->field.tqe_circ.tql_prev =3D &(elm)->field.tqe_circ; = \ } while (/*CONSTCOND*/0) =20 #define QTAILQ_REMOVE(head, elm, field) do { \ if (((elm)->field.tqe_next) !=3D NULL) \ - (elm)->field.tqe_next->field.tqe_prev =3D \ - (elm)->field.tqe_prev; \ + (elm)->field.tqe_next->field.tqe_circ.tql_prev =3D \ + (elm)->field.tqe_circ.tql_prev; \ else \ - (head)->tqh_last =3D (elm)->field.tqe_prev; \ - *(elm)->field.tqe_prev =3D (elm)->field.tqe_next; \ - (elm)->field.tqe_prev =3D NULL; \ + (head)->tqh_circ.tql_prev =3D (elm)->field.tqe_circ.tql_prev; \ + (elm)->field.tqe_circ.tql_prev->tql_next =3D (elm)->field.tqe_next= ; \ + (elm)->field.tqe_circ.tql_prev =3D NULL; \ } while (/*CONSTCOND*/0) =20 #define QTAILQ_FOREACH(var, head, field) \ @@ -428,13 +433,13 @@ struct { = \ (var) =3D (next_var)) =20 #define QTAILQ_FOREACH_REVERSE(var, head, headname, field) \ - for ((var) =3D (*(((struct headname *)((head)->tqh_last))->tqh_las= t)); \ + for ((var) =3D QTAILQ_LAST(head, headname); \ (var); \ - (var) =3D (*(((struct headname *)((var)->field.tqe_prev))-= >tqh_last))) + (var) =3D QTAILQ_PREV(var, headname, field)) =20 #define QTAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, prev_var) \ - for ((var) =3D (*(((struct headname *)((head)->tqh_last))->tqh_las= t)); \ - (var) && ((prev_var) =3D (*(((struct headname *)((var)->field= .tqe_prev))->tqh_last)), 1); \ + for ((var) =3D QTAILQ_LAST(head, headname); \ + (var) && ((prev_var) =3D QTAILQ_PREV(var, headname, field)); \ (var) =3D (prev_var)) =20 /* @@ -443,71 +448,49 @@ struct { = \ #define QTAILQ_EMPTY(head) ((head)->tqh_first =3D=3D NULL) #define QTAILQ_FIRST(head) ((head)->tqh_first) #define QTAILQ_NEXT(elm, field) ((elm)->field.tqe_next) -#define QTAILQ_IN_USE(elm, field) ((elm)->field.tqe_prev !=3D NULL) +#define QTAILQ_IN_USE(elm, field) ((elm)->field.tqe_circ.tql_prev != =3D NULL) =20 +#define QTAILQ_LINK_PREV(link) \ + ((link).tql_prev->tql_prev->tql_next) #define QTAILQ_LAST(head, headname) \ - (*(((struct headname *)((head)->tqh_last))->tqh_last)) + ((typeof((head)->tqh_first)) QTAILQ_LINK_PREV((head)->tqh_circ)) #define QTAILQ_PREV(elm, headname, field) \ - (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + ((typeof((elm)->field.tqe_next)) QTAILQ_LINK_PREV((elm)->field.tqe= _circ)) =20 #define field_at_offset(base, offset, type) = \ - ((type) (((char *) (base)) + (offset))) - -typedef struct DUMMY_Q_ENTRY DUMMY_Q_ENTRY; -typedef struct DUMMY_Q DUMMY_Q; - -struct DUMMY_Q_ENTRY { - QTAILQ_ENTRY(DUMMY_Q_ENTRY) next; -}; - -struct DUMMY_Q { - QTAILQ_HEAD(DUMMY_Q_HEAD, DUMMY_Q_ENTRY) head; -}; - -#define dummy_q ((DUMMY_Q *) 0) -#define dummy_qe ((DUMMY_Q_ENTRY *) 0) + ((type *) (((char *) (base)) + (offset))) =20 /* - * Offsets of layout of a tail queue head. - */ -#define QTAILQ_FIRST_OFFSET (offsetof(typeof(dummy_q->head), tqh_first)) -#define QTAILQ_LAST_OFFSET (offsetof(typeof(dummy_q->head), tqh_last)) -/* - * Raw access of elements of a tail queue + * Raw access of elements of a tail queue head. Offsets are all zero + * because it's a union. */ #define QTAILQ_RAW_FIRST(head) = \ - (*field_at_offset(head, QTAILQ_FIRST_OFFSET, void **)) -#define QTAILQ_RAW_TQH_LAST(head) = \ - (*field_at_offset(head, QTAILQ_LAST_OFFSET, void ***)) - -/* - * Offsets of layout of a tail queue element. - */ -#define QTAILQ_NEXT_OFFSET (offsetof(typeof(dummy_qe->next), tqe_next)) -#define QTAILQ_PREV_OFFSET (offsetof(typeof(dummy_qe->next), tqe_prev)) + field_at_offset(head, 0, void *) +#define QTAILQ_RAW_TQH_CIRC(head) = \ + field_at_offset(head, 0, QTailQLink) =20 /* * Raw access of elements of a tail entry */ #define QTAILQ_RAW_NEXT(elm, entry) = \ - (*field_at_offset(elm, entry + QTAILQ_NEXT_OFFSET, void **)) -#define QTAILQ_RAW_TQE_PREV(elm, entry) = \ - (*field_at_offset(elm, entry + QTAILQ_PREV_OFFSET, void ***)) + field_at_offset(elm, entry, void *) +#define QTAILQ_RAW_TQE_CIRC(elm, entry) = \ + field_at_offset(elm, entry, QTailQLink) /* - * Tail queue tranversal using pointer arithmetic. + * Tail queue traversal using pointer arithmetic. */ #define QTAILQ_RAW_FOREACH(elm, head, entry) = \ - for ((elm) =3D QTAILQ_RAW_FIRST(head); = \ + for ((elm) =3D *QTAILQ_RAW_FIRST(head); = \ (elm); = \ - (elm) =3D QTAILQ_RAW_NEXT(elm, entry)) + (elm) =3D *QTAILQ_RAW_NEXT(elm, entry)) /* * Tail queue insertion using pointer arithmetic. */ -#define QTAILQ_RAW_INSERT_TAIL(head, elm, entry) do { = \ - QTAILQ_RAW_NEXT(elm, entry) =3D NULL; = \ - QTAILQ_RAW_TQE_PREV(elm, entry) =3D QTAILQ_RAW_TQH_LAST(head); = \ - *QTAILQ_RAW_TQH_LAST(head) =3D (elm); = \ - QTAILQ_RAW_TQH_LAST(head) =3D &QTAILQ_RAW_NEXT(elm, entry); = \ +#define QTAILQ_RAW_INSERT_TAIL(head, elm, entry) do { = \ + *QTAILQ_RAW_NEXT(elm, entry) =3D NULL; = \ + QTAILQ_RAW_TQE_CIRC(elm, entry)->tql_prev =3D QTAILQ_RAW_TQH_CIRC(= head)->tql_prev; \ + QTAILQ_RAW_TQH_CIRC(head)->tql_prev->tql_next =3D (elm); = \ + QTAILQ_RAW_TQH_CIRC(head)->tql_prev =3D QTAILQ_RAW_TQE_CIRC(elm, e= ntry); \ } while (/*CONSTCOND*/0) =20 #endif /* QEMU_SYS_QUEUE_H */ diff --git a/include/qemu/rcu_queue.h b/include/qemu/rcu_queue.h index 904b337..2d386f3 100644 --- a/include/qemu/rcu_queue.h +++ b/include/qemu/rcu_queue.h @@ -206,47 +206,50 @@ extern "C" { #define QTAILQ_INSERT_HEAD_RCU(head, elm, field) do { \ (elm)->field.tqe_next =3D (head)->tqh_first; \ if ((elm)->field.tqe_next !=3D NULL) { \ - (head)->tqh_first->field.tqe_prev =3D &(elm)->field.tqe_next; \ + (head)->tqh_first->field.tqe_circ.tql_prev =3D \ + &(elm)->field.tqe_circ; \ } else { \ - (head)->tqh_last =3D &(elm)->field.tqe_next; \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ } \ atomic_rcu_set(&(head)->tqh_first, (elm)); \ - (elm)->field.tqe_prev =3D &(head)->tqh_first; \ + (elm)->field.tqe_circ.tql_prev =3D &(head)->tqh_circ; \ } while (/*CONSTCOND*/0) =20 -#define QTAILQ_INSERT_TAIL_RCU(head, elm, field) do { \ - (elm)->field.tqe_next =3D NULL; \ - (elm)->field.tqe_prev =3D (head)->tqh_last; \ - atomic_rcu_set((head)->tqh_last, (elm)); \ - (head)->tqh_last =3D &(elm)->field.tqe_next; \ +#define QTAILQ_INSERT_TAIL_RCU(head, elm, field) do { \ + (elm)->field.tqe_next =3D NULL; \ + (elm)->field.tqe_circ.tql_prev =3D (head)->tqh_circ.tql_prev; \ + atomic_rcu_set(&(head)->tqh_circ.tql_prev->tql_next, (elm)); \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ } while (/*CONSTCOND*/0) =20 #define QTAILQ_INSERT_AFTER_RCU(head, listelm, elm, field) do { \ (elm)->field.tqe_next =3D (listelm)->field.tqe_next; \ if ((elm)->field.tqe_next !=3D NULL) { \ - (elm)->field.tqe_next->field.tqe_prev =3D &(elm)->field.tqe_next; \ + (elm)->field.tqe_next->field.tqe_circ.tql_prev =3D \ + &(elm)->field.tqe_circ; \ } else { \ - (head)->tqh_last =3D &(elm)->field.tqe_next; \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ } \ atomic_rcu_set(&(listelm)->field.tqe_next, (elm)); \ - (elm)->field.tqe_prev =3D &(listelm)->field.tqe_next; \ + (elm)->field.tqe_circ.tql_prev =3D &(listelm)->field.tqe_circ; \ } while (/*CONSTCOND*/0) =20 -#define QTAILQ_INSERT_BEFORE_RCU(listelm, elm, field) do { \ - (elm)->field.tqe_prev =3D (listelm)->field.tqe_prev; \ - (elm)->field.tqe_next =3D (listelm); \ - atomic_rcu_set((listelm)->field.tqe_prev, (elm)); \ - (listelm)->field.tqe_prev =3D &(elm)->field.tqe_next; \ - } while (/*CONSTCOND*/0) +#define QTAILQ_INSERT_BEFORE_RCU(listelm, elm, field) do { \ + (elm)->field.tqe_circ.tql_prev =3D (listelm)->field.tqe_circ.tql_prev;= \ + (elm)->field.tqe_next =3D (listelm); = \ + atomic_rcu_set(&(listelm)->field.tqe_circ.tql_prev->tql_next, (elm)); \ + (listelm)->field.tqe_circ.tql_prev =3D &(elm)->field.tqe_circ; = \ +} while (/*CONSTCOND*/0) =20 #define QTAILQ_REMOVE_RCU(head, elm, field) do { \ if (((elm)->field.tqe_next) !=3D NULL) { \ - (elm)->field.tqe_next->field.tqe_prev =3D (elm)->field.tqe_prev; \ + (elm)->field.tqe_next->field.tqe_circ.tql_prev =3D \ + (elm)->field.tqe_circ.tql_prev; \ } else { \ - (head)->tqh_last =3D (elm)->field.tqe_prev; \ + (head)->tqh_circ.tql_prev =3D (elm)->field.tqe_circ.tql_prev; \ } \ - atomic_set((elm)->field.tqe_prev, (elm)->field.tqe_next); \ - (elm)->field.tqe_prev =3D NULL; \ + atomic_set(&(elm)->field.tqe_circ.tql_prev->tql_next, (elm)->field.tqe= _next); \ + (elm)->field.tqe_circ.tql_prev =3D NULL; \ } while (/*CONSTCOND*/0) =20 #define QTAILQ_FOREACH_RCU(var, head, field) \ diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h index 5c49369..1cb0b4a 100644 --- a/scripts/cocci-macro-file.h +++ b/scripts/cocci-macro-file.h @@ -94,18 +94,18 @@ struct { = \ * Tail queue definitions. */ #define QTAILQ_HEAD(name, type) \ -struct name { \ - type *tqh_first; /* first element */ \ - type **tqh_last; /* addr of last next element */ \ +union name { \ + struct type *tqh_first; /* first element */ \ + QTailQLink tqh_circ; /* link for last element */ \ } =20 #define QTAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).tqh_first } + { .tqh_circ =3D { NULL, &(head).tqh_circ } } =20 #define QTAILQ_ENTRY(type) \ -struct { \ - type *tqe_next; /* next element */ \ - type **tqe_prev; /* address of previous next element */ \ +union { \ + struct type *tqe_next; /* next element */ \ + QTailQLink tqe_circ; /* link for prev element */ \ } =20 /* From glib */ --=20 1.8.3.1