From owner-freebsd-arch@FreeBSD.ORG Tue May 8 17:55:23 2007 Return-Path: X-Original-To: freebsd-arch@freebsd.org Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 44CCB16A403; Tue, 8 May 2007 17:55:23 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.freebsd.org (Postfix) with ESMTP id C726313C465; Tue, 8 May 2007 17:55:22 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.8/8.13.8) with ESMTP id l48HtC22085124; Tue, 8 May 2007 13:55:13 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-arch@freebsd.org Date: Tue, 8 May 2007 11:28:25 -0400 User-Agent: KMail/1.9.6 References: <200705051617.34162.hselasky@c2i.net> <20070507202034.GA80846@kobe.laptop> <20070507202517.GA88340@kobe.laptop> In-Reply-To: <20070507202517.GA88340@kobe.laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200705081128.25708.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Tue, 08 May 2007 13:55:13 -0400 (EDT) X-Virus-Scanned: ClamAV 0.88.3/3222/Tue May 8 11:43:01 2007 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: Giorgos Keramidas , Hans Petter Selasky Subject: Re: Missing LIST_PREV() ? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 May 2007 17:55:23 -0000 On Monday 07 May 2007 04:25:18 pm Giorgos Keramidas wrote: > On 2007-05-07 23:20, Giorgos Keramidas wrote: > >On 2007-05-05 16:17, Hans Petter Selasky wrote: > >> Hi, > >> > >> Why should LISTs only be forward traversable? The following piece of > >> code make lists backward traversable: > >> > >> /sys/sys/queue.h: > >> > >> +#define LIST_PREV(head,elm,field) \ > >> + (((elm) == LIST_FIRST(head)) ? ((__typeof(elm))0) : \ > >> + ((__typeof(elm))(((uint8_t *)((elm)->field.le_prev)) - \ > >> + ((uint8_t *)&LIST_NEXT((__typeof(elm))0,field))))) > >> > >> Any comments? > > > > 1. The use of (uint8_t *) casts is relatively ugly. Looks like an ugly version of offsetof() > > 2. What does LIST_PREV give us that cannot be done with TAILQ_PREV() > > already? > > Even more importantly, which I missed in my original look > > (3) The use of the gcc-specific __typeof() extension makes this unusable > with other compilers. This can be fixed by passing the type as an argument which is what TAILQ_PREV() does: #define TAILQ_PREV(elm, headname, field) \ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) I'm not sure how portable offsetof() would be though. In general if you want this feature, you should just use a TAILQ though. TAILQ_ENTRY() is the same size as a LIST_ENTRY(), it just adds one more pointer to the HEAD structure. It is also specifically designed to make TAILQ_PREV() work w/o needing the offsetof() hack. -- John Baldwin