[PATCH v2 06/67] ui/vnc-jobs: narrow taking the queue lock

Marc-André Lureau posted 67 patches 17 hours ago
Maintainers: John Snow <jsnow@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Jan Kiszka <jan.kiszka@web.de>, Phil Dennis-Jordan <phil@philjordan.eu>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Gerd Hoffmann <kraxel@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Samuel Tardieu <sam@rfc1149.net>, "Hervé Poussineau" <hpoussin@reactos.org>, Aleksandar Rikalo <arikalo@gmail.com>, Laurent Vivier <laurent@vivier.eu>, Thomas Huth <th.huth+qemu@posteo.eu>, BALATON Zoltan <balaton@eik.bme.hu>, "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Alistair Francis <alistair@alistair23.me>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Fabiano Rosas <farosas@suse.de>
[PATCH v2 06/67] ui/vnc-jobs: narrow taking the queue lock
Posted by Marc-André Lureau 17 hours ago
It's not needed unless manipulating the queue.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 ui/vnc-jobs.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
index 28a4738f1ec..9c17d684c9e 100644
--- a/ui/vnc-jobs.c
+++ b/ui/vnc-jobs.c
@@ -83,26 +83,26 @@ VncJob *vnc_job_new(VncState *vs)
 
     assert(vs->magic == VNC_MAGIC);
     job->vs = vs;
-    vnc_lock_queue(queue);
     QLIST_INIT(&job->rectangles);
-    vnc_unlock_queue(queue);
     return job;
 }
 
+/*
+ * Do not call this after pushing the job.
+ */
 int vnc_job_add_rect(VncJob *job, int x, int y, int w, int h)
 {
     VncRectEntry *entry = g_new0(VncRectEntry, 1);
 
     trace_vnc_job_add_rect(job->vs, job, x, y, w, h);
+    assert(!QTAILQ_IN_USE(job, next));
 
     entry->rect.x = x;
     entry->rect.y = y;
     entry->rect.w = w;
     entry->rect.h = h;
 
-    vnc_lock_queue(queue);
     QLIST_INSERT_HEAD(&job->rectangles, entry, next);
-    vnc_unlock_queue(queue);
     return 1;
 }
 
@@ -120,16 +120,21 @@ static void vnc_job_free(VncJob *job)
     g_free(job);
 }
 
+/*
+ * Push a job onto the queue. Ownership of the job is transferred.
+ */
 void vnc_job_push(VncJob *job)
 {
-    vnc_lock_queue(queue);
+    assert(!QTAILQ_IN_USE(job, next));
+
     if (QLIST_EMPTY(&job->rectangles)) {
         vnc_job_free(job);
     } else {
+        vnc_lock_queue(queue);
         QTAILQ_INSERT_TAIL(&queue->jobs, job, next);
         qemu_cond_broadcast(&queue->cond);
+        vnc_unlock_queue(queue);
     }
-    vnc_unlock_queue(queue);
 }
 
 static bool vnc_has_job_locked(VncState *vs)

-- 
2.53.0