From patchwork Tue Mar 13 05:10:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Korolev X-Patchwork-Id: 146351 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 70F3FB6FB7 for ; Tue, 13 Mar 2012 16:11:10 +1100 (EST) Received: from localhost ([::1]:55690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7K0q-0007fJ-6x for incoming@patchwork.ozlabs.org; Tue, 13 Mar 2012 01:11:08 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7K0j-0007eq-1U for qemu-devel@nongnu.org; Tue, 13 Mar 2012 01:11:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7K0g-0004q6-U1 for qemu-devel@nongnu.org; Tue, 13 Mar 2012 01:11:00 -0400 Received: from usrksweb02.endace.com ([174.143.168.194]:44676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7K0g-0004pr-Ny for qemu-devel@nongnu.org; Tue, 13 Mar 2012 01:10:58 -0400 Received: from mail.et.endace.com ([131.203.121.41]) by usrksweb02.endace.com (8.14.3/8.14.3/Debian-9.2ubuntu1) with ESMTP id q2D54lEA002551; Tue, 13 Mar 2012 05:04:48 GMT Received: from [192.168.69.208] (192.168.69.208) by nzhmlmbx01.ad.endace.com (192.168.32.5) with Microsoft SMTP Server (TLS) id 14.1.218.12; Tue, 13 Mar 2012 18:10:47 +1300 Message-ID: <1331615428.26071.72.camel@nzhmlwks0057.ad.endace.com> From: Alexey Korolev To: Date: Tue, 13 Mar 2012 18:10:28 +1300 In-Reply-To: <1331613556.26071.43.camel@nzhmlwks0057.ad.endace.com> References: <1331613556.26071.43.camel@nzhmlwks0057.ad.endace.com> X-Mailer: Evolution 3.2.2- MIME-Version: 1.0 X-Originating-IP: [192.168.69.208] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 174.143.168.194 Cc: sfd@endace.com, seabios@seabios.org, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 6/6] Use linked lists in pmm.c and stack.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: alexey.korolev@endace.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch simplifies a bit complicated code in pmm.c and stack.c Signed-off-by: Alexey Korolev --- src/pmm.c | 29 +++++++++-------------------- src/stacks.c | 8 ++------ 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/pmm.c b/src/pmm.c index c649fd8..996981c 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -44,24 +44,20 @@ static void * allocSpace(struct zone_s *zone, u32 size, u32 align, struct allocinfo_s *fill) { struct allocinfo_s *info; - for (info = zone->info; info; info = info->next) { + list_foreach_entry(zone->info, info) { void *dataend = info->dataend; void *allocend = info->allocend; void *newallocend = (void*)ALIGN_DOWN((u32)allocend - size, align); if (newallocend >= dataend && newallocend <= allocend) { // Found space - now reserve it. - struct allocinfo_s **pprev = info->pprev; if (!fill) fill = newallocend; - fill->next = info; - fill->pprev = pprev; + list_add_before(info, fill); fill->data = newallocend; fill->dataend = newallocend + size; fill->allocend = allocend; info->allocend = newallocend; - info->pprev = &fill->next; - *pprev = fill; return newallocend; } } @@ -73,13 +69,9 @@ static void freeSpace(struct allocinfo_s *info) { struct allocinfo_s *next = info->next; - struct allocinfo_s **pprev = info->pprev; - *pprev = next; - if (next) { - if (next->allocend == info->data) + if (next && (next->allocend == info->data)) next->allocend = info->allocend; - next->pprev = pprev; - } + list_del(info); } // Add new memory to a zone @@ -97,13 +89,12 @@ addSpace(struct zone_s *zone, void *start, void *end) // Add space using temporary allocation info. struct allocdetail_s tempdetail; - tempdetail.datainfo.next = info; - tempdetail.datainfo.pprev = pprev; tempdetail.datainfo.data = tempdetail.datainfo.dataend = start; tempdetail.datainfo.allocend = end; - *pprev = &tempdetail.datainfo; - if (info) - info->pprev = &tempdetail.datainfo.next; + + tempdetail.datainfo.data = tempdetail.datainfo.dataend = start; + tempdetail.datainfo.allocend = end; + list_add_head(pprev, &tempdetail.datainfo); // Allocate final allocation info. struct allocdetail_s *detail = allocSpace( @@ -112,9 +103,7 @@ addSpace(struct zone_s *zone, void *start, void *end) detail = allocSpace(&ZoneTmpLow, sizeof(*detail) , MALLOC_MIN_ALIGN, NULL); if (!detail) { - *tempdetail.datainfo.pprev = tempdetail.datainfo.next; - if (tempdetail.datainfo.next) - tempdetail.datainfo.next->pprev = tempdetail.datainfo.pprev; + list_del(&tempdetail.datainfo); warn_noalloc(); return; } diff --git a/src/stacks.c b/src/stacks.c index 17f1a4a..2b10188 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -240,8 +240,7 @@ yield(void) static void __end_thread(struct thread_info *old) { - old->next->pprev = old->pprev; - *old->pprev = old->next; + list_del(old); free(old); dprintf(DEBUG_thread, "\\%08x/ End thread\n", (u32)old); if (MainThread.next == &MainThread) @@ -262,10 +261,7 @@ run_thread(void (*func)(void*), void *data) thread->stackpos = (void*)thread + THREADSTACKSIZE; struct thread_info *cur = getCurThread(); - thread->next = cur; - thread->pprev = cur->pprev; - cur->pprev = &thread->next; - *thread->pprev = thread; + list_add_before(cur, thread); dprintf(DEBUG_thread, "/%08x\\ Start thread\n", (u32)thread); asm volatile(