From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJsqk-0000IU-N6 for qemu-devel@nongnu.org; Mon, 27 Jul 2015 20:34:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJsqh-0005Rh-1x for qemu-devel@nongnu.org; Mon, 27 Jul 2015 20:34:30 -0400 Received: from mail-qg0-x22a.google.com ([2607:f8b0:400d:c04::22a]:35546) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJsqg-0005RV-Ud for qemu-devel@nongnu.org; Mon, 27 Jul 2015 20:34:26 -0400 Received: by qgii95 with SMTP id i95so64572396qgi.2 for ; Mon, 27 Jul 2015 17:34:26 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 28 Jul 2015 02:32:31 +0200 Message-Id: <1438043577-28636-20-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1438043577-28636-1-git-send-email-marcandre.lureau@redhat.com> References: <1438043577-28636-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v2 19/45] ivshmem: beautify a bit the code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , drjones@redhat.com, cam@cs.ualberta.ca, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com From: Marc-André Lureau Use more explicit variables. Signed-off-by: Marc-André Lureau --- hw/misc/ivshmem.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 6f3d2fe..84d8ff1 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -489,9 +489,10 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) { IVShmemState *s = opaque; int incoming_fd; - int guest_max_eventfd; + int nth_eventfd; long incoming_posn; Error *err = NULL; + Peer *peer; if (!fifo_update_and_get(s, buf, size, &incoming_posn, sizeof(incoming_posn))) { @@ -518,6 +519,8 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) } } + peer = &s->peers[incoming_posn]; + if (incoming_fd == -1) { /* if posn is positive and unseen before then this is our posn*/ if (incoming_posn >= 0 && s->vm_id == -1) { @@ -565,27 +568,22 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) return; } - /* each guest has an array of eventfds, and we keep track of how many - * guests for each VM */ - guest_max_eventfd = s->peers[incoming_posn].nb_eventfds; + /* get a new eventfd */ + nth_eventfd = peer->nb_eventfds++; /* this is an eventfd for a particular guest VM */ IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn, - guest_max_eventfd, incoming_fd); - event_notifier_init_fd(&s->peers[incoming_posn].eventfds[guest_max_eventfd], - incoming_fd); - - /* increment count for particular guest */ - s->peers[incoming_posn].nb_eventfds++; + nth_eventfd, incoming_fd); + event_notifier_init_fd(&peer->eventfds[nth_eventfd], incoming_fd); if (incoming_posn == s->vm_id) { - s->eventfd_chr[guest_max_eventfd] = create_eventfd_chr_device(s, - &s->peers[s->vm_id].eventfds[guest_max_eventfd], - guest_max_eventfd); + s->eventfd_chr[nth_eventfd] = create_eventfd_chr_device(s, + &s->peers[s->vm_id].eventfds[nth_eventfd], + nth_eventfd); } if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) { - ivshmem_add_eventfd(s, incoming_posn, guest_max_eventfd); + ivshmem_add_eventfd(s, incoming_posn, nth_eventfd); } } -- 2.4.3