From patchwork Thu Feb 4 14:46:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 44501 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 1A844B7D46 for ; Fri, 5 Feb 2010 01:58:02 +1100 (EST) Received: from localhost ([127.0.0.1]:35388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nd32S-00009R-7p for incoming@patchwork.ozlabs.org; Thu, 04 Feb 2010 09:50:36 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nd2zk-000849-N5 for qemu-devel@nongnu.org; Thu, 04 Feb 2010 09:47:48 -0500 Received: from [199.232.76.173] (port=33537 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nd2zk-00083o-80 for qemu-devel@nongnu.org; Thu, 04 Feb 2010 09:47:48 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nd2zh-0002pv-P0 for qemu-devel@nongnu.org; Thu, 04 Feb 2010 09:47:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34404) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nd2zh-0002pj-7T for qemu-devel@nongnu.org; Thu, 04 Feb 2010 09:47:45 -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 o14Eli2S029131 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 4 Feb 2010 09:47:44 -0500 Received: from localhost (vpn-233-103.phx2.redhat.com [10.3.233.103]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o14ElgZ2002745; Thu, 4 Feb 2010 09:47:43 -0500 From: Amit Shah To: qemu-devel@nongnu.org Date: Thu, 4 Feb 2010 20:16:33 +0530 Message-Id: <1265294793-28164-1-git-send-email-amit.shah@redhat.com> 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. Cc: Amit Shah Subject: [Qemu-devel] [PATCH] vnc: Migrate to using QTAILQ instead of custom implementation 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 Just a 1-1 conversion for now. Signed-off-by: Amit Shah --- vnc.c | 73 ++++++++++++++++++++++++----------------------------------------- vnc.h | 5 ++- 2 files changed, 30 insertions(+), 48 deletions(-) diff --git a/vnc.c b/vnc.c index 92facde..16fc4e9 100644 --- a/vnc.c +++ b/vnc.c @@ -356,17 +356,14 @@ void do_info_vnc(Monitor *mon, QObject **ret_data) *ret_data = qobject_from_jsonf("{ 'enabled': false }"); } else { QList *clist; + VncState *client; clist = qlist_new(); - if (vnc_display->clients) { - VncState *client = vnc_display->clients; - while (client) { - if (client->info) { - /* incref so that it's not freed by upper layers */ - qobject_incref(client->info); - qlist_append_obj(clist, client->info); - } - client = client->next; + QTAILQ_FOREACH(client, &vnc_display->clients, next) { + if (client->info) { + /* incref so that it's not freed by upper layers */ + qobject_incref(client->info); + qlist_append_obj(clist, client->info); } } @@ -519,7 +516,7 @@ static void vnc_dpy_resize(DisplayState *ds) { int size_changed; VncDisplay *vd = ds->opaque; - VncState *vs = vd->clients; + VncState *vs; /* server surface */ if (!vd->server) @@ -540,7 +537,7 @@ static void vnc_dpy_resize(DisplayState *ds) *(vd->guest.ds) = *(ds->surface); memset(vd->guest.dirty, 0xFF, sizeof(vd->guest.dirty)); - while (vs != NULL) { + QTAILQ_FOREACH(vs, &vd->clients, next) { vnc_colordepth(vs); if (size_changed) { if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_RESIZE)) { @@ -553,7 +550,6 @@ static void vnc_dpy_resize(DisplayState *ds) } } memset(vs->dirty, 0xFF, sizeof(vs->dirty)); - vs = vs->next; } } @@ -867,8 +863,7 @@ static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int int cmp_bytes; vnc_refresh_server_surface(vd); - for (vs = vd->clients; vs != NULL; vs = vn) { - vn = vs->next; + QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) { if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) { vs->force_update = 1; vnc_update_client(vs, 1); @@ -912,11 +907,10 @@ static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int if (memcmp(src_row, dst_row, cmp_bytes) == 0) continue; memmove(dst_row, src_row, cmp_bytes); - vs = vd->clients; - while (vs != NULL) { - if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) + QTAILQ_FOREACH(vs, &vd->clients, next) { + if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) { vnc_set_bit(vs->dirty[y], ((x + dst_x) / 16)); - vs = vs->next; + } } } src_row += pitch - w * depth; @@ -924,9 +918,10 @@ static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int y += inc; } - for (vs = vd->clients; vs != NULL; vs = vs->next) { - if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) + QTAILQ_FOREACH(vs, &vd->clients, next) { + if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) { vnc_copy(vs, src_x, src_y, dst_x, dst_y, w, h); + } } } @@ -1109,19 +1104,11 @@ static void vnc_disconnect_finish(VncState *vs) #endif /* CONFIG_VNC_SASL */ audio_del(vs); - VncState *p, *parent = NULL; - for (p = vs->vd->clients; p != NULL; p = p->next) { - if (p == vs) { - if (parent) - parent->next = p->next; - else - vs->vd->clients = p->next; - break; - } - parent = p; - } - if (!vs->vd->clients) + QTAILQ_REMOVE(&vs->vd->clients, vs, next); + + if (QTAILQ_EMPTY(&vs->vd->clients)) { dcl->idle = 1; + } vnc_remove_timer(vs->vd); qemu_free(vs); @@ -2299,7 +2286,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd) uint8_t *server_row; int cmp_bytes; uint32_t width_mask[VNC_DIRTY_WORDS]; - VncState *vs = NULL; + VncState *vs; int has_dirty = 0; /* @@ -2328,10 +2315,8 @@ static int vnc_refresh_server_surface(VncDisplay *vd) if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0) continue; memcpy(server_ptr, guest_ptr, cmp_bytes); - vs = vd->clients; - while (vs != NULL) { + QTAILQ_FOREACH(vs, &vd->clients, next) { vnc_set_bit(vs->dirty[y], (x / 16)); - vs = vs->next; } has_dirty++; } @@ -2345,19 +2330,16 @@ static int vnc_refresh_server_surface(VncDisplay *vd) static void vnc_refresh(void *opaque) { VncDisplay *vd = opaque; - VncState *vs = NULL, *vn = NULL; - int has_dirty = 0, rects = 0; + VncState *vs, *vn; + int has_dirty, rects = 0; vga_hw_update(); has_dirty = vnc_refresh_server_surface(vd); - vs = vd->clients; - while (vs != NULL) { - vn = vs->next; + QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) { rects += vnc_update_client(vs, has_dirty); /* vs might be free()ed here */ - vs = vn; } /* vd->timer could be NULL now if the last client disconnected, * in this case don't update the timer */ @@ -2379,7 +2361,7 @@ static void vnc_refresh(void *opaque) static void vnc_init_timer(VncDisplay *vd) { vd->timer_interval = VNC_REFRESH_INTERVAL_BASE; - if (vd->timer == NULL && vd->clients != NULL) { + if (vd->timer == NULL && !QTAILQ_EMPTY(&vd->clients)) { vd->timer = qemu_new_timer(rt_clock, vnc_refresh, vd); vnc_refresh(vd); } @@ -2387,7 +2369,7 @@ static void vnc_init_timer(VncDisplay *vd) static void vnc_remove_timer(VncDisplay *vd) { - if (vd->timer != NULL && vd->clients == NULL) { + if (vd->timer != NULL && QTAILQ_EMPTY(&vd->clients)) { qemu_del_timer(vd->timer); qemu_free_timer(vd->timer); vd->timer = NULL; @@ -2417,8 +2399,7 @@ static void vnc_connect(VncDisplay *vd, int csock) vs->as.fmt = AUD_FMT_S16; vs->as.endianness = 0; - vs->next = vd->clients; - vd->clients = vs; + QTAILQ_INSERT_HEAD(&vd->clients, vs, next); vga_hw_update(); diff --git a/vnc.h b/vnc.h index 1210824..92caf2f 100644 --- a/vnc.h +++ b/vnc.h @@ -28,6 +28,7 @@ #define __QEMU_VNC_H #include "qemu-common.h" +#include "qemu-queue.h" #include "console.h" #include "monitor.h" #include "audio/audio.h" @@ -92,11 +93,11 @@ struct VncSurface struct VncDisplay { + QTAILQ_HEAD(, VncState) clients; QEMUTimer *timer; int timer_interval; int lsock; DisplayState *ds; - VncState *clients; kbd_layout_t *kbd_layout; struct VncSurface guest; /* guest visible surface (aka ds->surface) */ @@ -165,7 +166,7 @@ struct VncState Buffer zlib_tmp; z_stream zlib_stream[4]; - VncState *next; + QTAILQ_ENTRY(VncState) next; };