From: Samuel Thibault Subject: Re: [PATCH 05/11] mini-os/xenbus: Use MINIOS_LIST for the list of watches Date: Thu, 26 Jun 2014 14:06:52 +0200 Message-ID: <20140626120652.GU6046@type.bordeaux.inria.fr> References: <1403291090-8657-1-git-send-email-ian.jackson@eu.citrix.com> <1403291090-8657-6-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X08SI-0002GB-Pw for xen-devel@lists.xenproject.org; Thu, 26 Jun 2014 12:07:06 +0000 Content-Disposition: inline In-Reply-To: <1403291090-8657-6-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: xen-devel@lists.xenproject.org, Keir Fraser , Ian Campbell List-Id: xen-devel@lists.xenproject.org Ian Jackson, le Fri 20 Jun 2014 20:04:44 +0100, a =E9crit : > Remove the open-coded singly-linked list manipulation. > = > We replace it with a doubly-linked list because in forthcoming patches > we are going to want the ability to remove a watch from the middle of > the list without hunting for it first. > = > Signed-off-by: Ian Jackson Acked-by: Samuel Thibault > --- > xen/xenbus/xenbus.c | 19 ++++++++++--------- > 1 file changed, 10 insertions(+), 9 deletions(-) > = > diff --git a/xen/xenbus/xenbus.c b/xen/xenbus/xenbus.c > index 8a14c3b..66fdc8a 100644 > --- a/xen/xenbus/xenbus.c > +++ b/xen/xenbus/xenbus.c > @@ -49,11 +49,12 @@ static spinlock_t xb_lock =3D SPIN_LOCK_UNLOCKED; /* = protects xenbus req ring */ > DECLARE_WAIT_QUEUE_HEAD(xenbus_watch_queue); > = > struct xenbus_event_queue xenbus_events; > -static struct watch { > +struct watch { > char *token; > struct xenbus_event_queue *events; > - struct watch *next; > -} *watches; > + MINIOS_LIST_ENTRY(watch) entry; > +}; > +static MINIOS_LIST_HEAD(, watch) watches; > struct xenbus_req_info = > { > int in_use:1; > @@ -248,7 +249,7 @@ static void xenbus_thread_func(void *ign) > = > xenstore_buf->rsp_cons +=3D msg.len + sizeof(msg); > = > - for (watch =3D watches; watch; watch =3D watch->next) > + MINIOS_LIST_FOREACH(watch, &watches, entry) > if (!strcmp(watch->token, event->token)) { > events =3D watch->events; > break; > @@ -586,8 +587,8 @@ char* xenbus_watch_path_token( xenbus_transaction_t x= bt, const char *path, const > = > watch->token =3D strdup(token); > watch->events =3D events; > - watch->next =3D watches; > - watches =3D watch; > + > + MINIOS_LIST_INSERT_HEAD(&watches, watch, entry); > = > rep =3D xenbus_msg_reply(XS_WATCH, xbt, req, ARRAY_SIZE(req)); > = > @@ -607,7 +608,7 @@ char* xenbus_unwatch_path_token( xenbus_transaction_t= xbt, const char *path, con > {token, strlen(token) + 1}, > }; > = > - struct watch *watch, **prev; > + struct watch *watch; > = > char *msg; > = > @@ -617,10 +618,10 @@ char* xenbus_unwatch_path_token( xenbus_transaction= _t xbt, const char *path, con > if (msg) return msg; > free(rep); > = > - for (prev =3D &watches, watch =3D *prev; watch; prev =3D &watch->nex= t, watch =3D *prev) > + MINIOS_LIST_FOREACH(watch, &watches, entry) > if (!strcmp(watch->token, token)) { > free(watch->token); > - *prev =3D watch->next; > + MINIOS_LIST_REMOVE(watch, entry); > free(watch); > break; > } > -- = > 1.7.10.4 > = > = > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel > = -- = Samuel The problem with America is stupidity. I'm not saying there should = be a capital punishment for stupidity, but why don't we just take the safet= y labels off of everything and let the problem solve itself?