From patchwork Wed Mar 10 10:03:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 47215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DB741B7CCD for ; Wed, 10 Mar 2010 21:09:15 +1100 (EST) Received: from localhost ([127.0.0.1]:54591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpIox-0004nX-Tx for incoming@patchwork.ozlabs.org; Wed, 10 Mar 2010 05:07:19 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NpIlM-0003on-6w for qemu-devel@nongnu.org; Wed, 10 Mar 2010 05:03:36 -0500 Received: from [199.232.76.173] (port=49315 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpIlL-0003oV-L7 for qemu-devel@nongnu.org; Wed, 10 Mar 2010 05:03:35 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NpIlJ-0001qj-Dr for qemu-devel@nongnu.org; Wed, 10 Mar 2010 05:03:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47986) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NpIlI-0001qa-Nb for qemu-devel@nongnu.org; Wed, 10 Mar 2010 05:03:33 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2AA3Vf1017757 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 10 Mar 2010 05:03:32 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2AA3SbC017099; Wed, 10 Mar 2010 05:03:30 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 10 Mar 2010 11:03:15 +0100 Message-Id: <4f197c437a4d2f813ce518b4fd2d86fc225f500e.1268214633.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 01/14] Convert io handlers to QLIST X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Juan Quintela --- vl.c | 35 ++++++++++++++--------------------- 1 files changed, 14 insertions(+), 21 deletions(-) diff --git a/vl.c b/vl.c index 10d8e34..83ff652 100644 --- a/vl.c +++ b/vl.c @@ -2597,10 +2597,12 @@ typedef struct IOHandlerRecord { void *opaque; /* temporary data */ struct pollfd *ufd; - struct IOHandlerRecord *next; + QTAILQ_ENTRY(IOHandlerRecord) next; } IOHandlerRecord; -static IOHandlerRecord *first_io_handler; +static QTAILQ_HEAD(, IOHandlerRecord) io_handlers = + QTAILQ_HEAD_INITIALIZER(io_handlers); + /* XXX: fd_read_poll should be suppressed, but an API change is necessary in the character devices to suppress fd_can_read(). */ @@ -2610,28 +2612,22 @@ int qemu_set_fd_handler2(int fd, IOHandler *fd_write, void *opaque) { - IOHandlerRecord **pioh, *ioh; + IOHandlerRecord *ioh; if (!fd_read && !fd_write) { - pioh = &first_io_handler; - for(;;) { - ioh = *pioh; - if (ioh == NULL) - break; + QTAILQ_FOREACH(ioh, &io_handlers, next) { if (ioh->fd == fd) { ioh->deleted = 1; break; } - pioh = &ioh->next; } } else { - for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { + QTAILQ_FOREACH(ioh, &io_handlers, next) { if (ioh->fd == fd) goto found; } ioh = qemu_mallocz(sizeof(IOHandlerRecord)); - ioh->next = first_io_handler; - first_io_handler = ioh; + QTAILQ_INSERT_TAIL(&io_handlers, ioh, next); found: ioh->fd = fd; ioh->fd_read_poll = fd_read_poll; @@ -3822,7 +3818,7 @@ void main_loop_wait(int timeout) FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); - for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { + QTAILQ_FOREACH(ioh, &io_handlers, next) { if (ioh->deleted) continue; if (ioh->fd_read && @@ -3848,9 +3844,9 @@ void main_loop_wait(int timeout) ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); qemu_mutex_lock_iothread(); if (ret > 0) { - IOHandlerRecord **pioh; + IOHandlerRecord *pioh; - for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { + QTAILQ_FOREACH(ioh, &io_handlers, next) { if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) { ioh->fd_read(ioh->opaque); } @@ -3860,14 +3856,11 @@ void main_loop_wait(int timeout) } /* remove deleted IO handlers */ - pioh = &first_io_handler; - while (*pioh) { - ioh = *pioh; + QTAILQ_FOREACH_SAFE(ioh, &io_handlers, next, pioh) { if (ioh->deleted) { - *pioh = ioh->next; + QTAILQ_REMOVE(&io_handlers, ioh, next); qemu_free(ioh); - } else - pioh = &ioh->next; + } } }