From 0f8cc78db61b12fe53ed8a1db4875f93c8a0e07b Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 17 Feb 2012 12:53:54 +0100 Subject: [PATCH 01/11] vnc: Migrate to using QTAILQ instead of custom implementation RH-Author: Gerd Hoffmann Message-id: <1329483235-24945-2-git-send-email-kraxel@redhat.com> Patchwork-id: 37413 O-Subject: [RHEL-6.3 qemu-kvm PATCH 1/2] vnc: Migrate to using QTAILQ instead of custom implementation Bugzilla: 653779 RH-Acked-by: Alex Williamson RH-Acked-by: Laszlo Ersek RH-Acked-by: Markus Armbruster Just a 1-1 conversion for now. Signed-off-by: Amit Shah Signed-off-by: Anthony Liguori (cherry picked from commit 41b4bef65f1e2b2f313cae0f88a1c76a9cb3f222) Conflicts: vnc.c vnc.h --- vnc.c | 74 ++++++++++++++++++++++++---------------------------------------- vnc.h | 5 ++- 2 files changed, 31 insertions(+), 48 deletions(-) Signed-off-by: Michal Novotny --- vnc.c | 74 ++++++++++++++++++++++++---------------------------------------- vnc.h | 5 ++- 2 files changed, 31 insertions(+), 48 deletions(-) diff --git a/vnc.c b/vnc.c index e4ad937..85ec4b2 100644 --- a/vnc.c +++ b/vnc.c @@ -327,17 +327,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); } } @@ -510,7 +507,7 @@ static void vnc_desktop_resize(VncState *vs) static void vnc_dpy_resize(DisplayState *ds) { VncDisplay *vd = ds->opaque; - VncState *vs = vd->clients; + VncState *vs; /* server surface */ if (!vd->server) @@ -529,11 +526,10 @@ 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); vnc_desktop_resize(vs); memset(vs->dirty, 0xFF, sizeof(vs->dirty)); - vs = vs->next; } } @@ -847,8 +843,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); @@ -892,11 +887,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; @@ -904,9 +898,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); + } } } @@ -1092,19 +1087,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; + } qemu_remove_mouse_mode_change_notifier(&vs->mouse_mode_notifier); vnc_remove_timer(vs->vd); @@ -2307,7 +2294,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; /* @@ -2336,10 +2323,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++; } @@ -2353,19 +2338,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 */ @@ -2387,7 +2369,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_dpy_resize(vd->ds); vnc_refresh(vd); @@ -2396,7 +2378,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; @@ -2426,8 +2408,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(); @@ -2475,6 +2456,7 @@ void vnc_display_init(DisplayState *ds) vs->ds = ds; vs->expires = TIME_MAX; + QTAILQ_INIT(&vs->clients); if (keyboard_layout) vs->kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout); diff --git a/vnc.h b/vnc.h index a752cef..2be435d 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) */ @@ -170,7 +171,7 @@ struct VncState z_stream zlib_stream[4]; Notifier mouse_mode_notifier; - VncState *next; + QTAILQ_ENTRY(VncState) next; }; -- 1.7.7.6