From patchwork Sun Feb 8 04:35:53 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 22563 X-Patchwork-Delegate: jk@ozlabs.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id EC98DDE11A for ; Sun, 8 Feb 2009 15:39:39 +1100 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BC001DDE1A; Sun, 8 Feb 2009 15:39:10 +1100 (EST) Received: from hera.kernel.org (IDENT:U2FsdGVkX19+Pf8SEWtxC6cVAFJz52lOrgXdmMc4mXc@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n184d2TI011884 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 8 Feb 2009 04:39:02 GMT Received: (from geoff@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n184d2e9011882; Sun, 8 Feb 2009 04:39:02 GMT Message-Id: <20090208043550.908398902@am.sony.com> References: <20090208043550.681477743@am.sony.com> In-Reply-To: <20090208043550.681477743@am.sony.com> User-Agent: quilt/0.46-1 Date: Sat, 07 Feb 2009 20:35:53 -0800 From: Geoff Levand To: Jeremy Kerr Content-Disposition: inline; filename=list-add-tail.diff X-Virus-Scanned: ClamAV 0.93.3/8963/Sat Feb 7 05:53:02 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Sun, 08 Feb 2009 04:39:04 +0000 (UTC) Cc: cbe-oss-dev@ozlabs.org Subject: [Cbe-oss-dev] [patch 3/4] petitboot: Add list insert routines X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Add new list insertion routines list_insert_before(), list_insert_after(), and list_add_tail(). Also, change list_add() to use list_insert_after(). Signed-off-by: Geoff Levand --- lib/list/list.c | 18 ++++++++++++------ lib/list/list.h | 14 +++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) --- a/lib/list/list.c +++ b/lib/list/list.c @@ -7,13 +7,20 @@ void list_init(struct list *list) list->head.prev = &list->head; } -void list_add(struct list *list, struct list_item *new) +void list_insert_before(struct list_item *next, struct list_item *new) { - new->next = list->head.next; - new->prev = &list->head; + new->next = next; + new->prev = next->prev; + next->prev->next = new; + next->prev = new; +} - list->head.next->prev = new; - list->head.next = new; +void list_insert_after(struct list_item *prev, struct list_item *new) +{ + new->next = prev->next; + new->prev = prev; + prev->next->prev = new; + prev->next = new; } void list_remove(struct list_item *item) @@ -21,4 +28,3 @@ void list_remove(struct list_item *item) item->next->prev = item->prev; item->prev->next = item->next; } - --- a/lib/list/list.h +++ b/lib/list/list.h @@ -31,9 +31,17 @@ struct list { pos = list_entry(pos->member.next, typeof(*pos), member)) void list_init(struct list *list); - -void list_add(struct list *list, struct list_item *item); - +void list_insert_before(struct list_item *next, struct list_item *new); +void list_insert_after(struct list_item *prev, struct list_item *new); void list_remove(struct list_item *item); +static inline void list_add(struct list *list, struct list_item *new) +{ + list_insert_after(&list->head, new); +} +static inline void list_add_tail(struct list *list, struct list_item *new) +{ + list_insert_before(&list->head, new); +} + #endif /* _LIST_H */