Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU VNC display driver |
| 3 | * |
| 4 | * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws> |
| 5 | * Copyright (C) 2006 Fabrice Bellard |
| 6 | * Copyright (C) 2009 Red Hat, Inc |
| 7 | * Copyright (C) 2010 Corentin Chary <corentin.chary@gmail.com> |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | * of this software and associated documentation files (the "Software"), to deal |
| 11 | * in the Software without restriction, including without limitation the rights |
| 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | * copies of the Software, and to permit persons to whom the Software is |
| 14 | * furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included in |
| 17 | * all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | * THE SOFTWARE. |
| 26 | */ |
| 27 | |
| 28 | |
Peter Maydell | e16f4c8 | 2016-01-29 17:49:51 +0000 | [diff] [blame] | 29 | #include "qemu/osdep.h" |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 30 | #include "vnc.h" |
| 31 | #include "vnc-jobs.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 32 | #include "qemu/sockets.h" |
Gerd Hoffmann | d903401 | 2015-10-30 12:10:04 +0100 | [diff] [blame] | 33 | #include "qemu/main-loop.h" |
Markus Armbruster | a0b1a66 | 2015-03-17 18:16:21 +0100 | [diff] [blame] | 34 | #include "block/aio.h" |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Locking: |
| 38 | * |
Peter Maydell | 11f6697 | 2012-10-18 17:40:53 +0100 | [diff] [blame] | 39 | * There are three levels of locking: |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 40 | * - jobs queue lock: for each operation on the queue (push, pop, isEmpty?) |
| 41 | * - VncDisplay global lock: mainly used for framebuffer updates to avoid |
| 42 | * screen corruption if the framebuffer is updated |
Peter Maydell | 11f6697 | 2012-10-18 17:40:53 +0100 | [diff] [blame] | 43 | * while the worker is doing something. |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 44 | * - VncState::output lock: used to make sure the output buffer is not corrupted |
Peter Maydell | 11f6697 | 2012-10-18 17:40:53 +0100 | [diff] [blame] | 45 | * if two threads try to write on it at the same time |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 46 | * |
Peter Maydell | 11f6697 | 2012-10-18 17:40:53 +0100 | [diff] [blame] | 47 | * While the VNC worker thread is working, the VncDisplay global lock is held |
| 48 | * to avoid screen corruption (this does not block vnc_refresh() because it |
| 49 | * uses trylock()) but the output lock is not held because the thread works on |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 50 | * its own output buffer. |
| 51 | * When the encoding job is done, the worker thread will hold the output lock |
| 52 | * and copy its output buffer in vs->output. |
Peter Maydell | 11f6697 | 2012-10-18 17:40:53 +0100 | [diff] [blame] | 53 | */ |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 54 | |
| 55 | struct VncJobQueue { |
| 56 | QemuCond cond; |
| 57 | QemuMutex mutex; |
| 58 | QemuThread thread; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 59 | bool exit; |
| 60 | QTAILQ_HEAD(, VncJob) jobs; |
| 61 | }; |
| 62 | |
| 63 | typedef struct VncJobQueue VncJobQueue; |
| 64 | |
| 65 | /* |
| 66 | * We use a single global queue, but most of the functions are |
Peter Maydell | 11f6697 | 2012-10-18 17:40:53 +0100 | [diff] [blame] | 67 | * already reentrant, so we can easily add more than one encoding thread |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 68 | */ |
| 69 | static VncJobQueue *queue; |
| 70 | |
| 71 | static void vnc_lock_queue(VncJobQueue *queue) |
| 72 | { |
| 73 | qemu_mutex_lock(&queue->mutex); |
| 74 | } |
| 75 | |
| 76 | static void vnc_unlock_queue(VncJobQueue *queue) |
| 77 | { |
| 78 | qemu_mutex_unlock(&queue->mutex); |
| 79 | } |
| 80 | |
| 81 | VncJob *vnc_job_new(VncState *vs) |
| 82 | { |
Markus Armbruster | fedf0d3 | 2015-11-03 17:12:03 +0100 | [diff] [blame] | 83 | VncJob *job = g_new0(VncJob, 1); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 84 | |
Gerd Hoffmann | f31f9c1 | 2018-05-07 12:22:54 +0200 | [diff] [blame] | 85 | assert(vs->magic == VNC_MAGIC); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 86 | job->vs = vs; |
| 87 | vnc_lock_queue(queue); |
| 88 | QLIST_INIT(&job->rectangles); |
| 89 | vnc_unlock_queue(queue); |
| 90 | return job; |
| 91 | } |
| 92 | |
| 93 | int vnc_job_add_rect(VncJob *job, int x, int y, int w, int h) |
| 94 | { |
Markus Armbruster | fedf0d3 | 2015-11-03 17:12:03 +0100 | [diff] [blame] | 95 | VncRectEntry *entry = g_new0(VncRectEntry, 1); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 96 | |
| 97 | entry->rect.x = x; |
| 98 | entry->rect.y = y; |
| 99 | entry->rect.w = w; |
| 100 | entry->rect.h = h; |
| 101 | |
| 102 | vnc_lock_queue(queue); |
| 103 | QLIST_INSERT_HEAD(&job->rectangles, entry, next); |
| 104 | vnc_unlock_queue(queue); |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | void vnc_job_push(VncJob *job) |
| 109 | { |
| 110 | vnc_lock_queue(queue); |
| 111 | if (queue->exit || QLIST_EMPTY(&job->rectangles)) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 112 | g_free(job); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 113 | } else { |
| 114 | QTAILQ_INSERT_TAIL(&queue->jobs, job, next); |
| 115 | qemu_cond_broadcast(&queue->cond); |
| 116 | } |
| 117 | vnc_unlock_queue(queue); |
| 118 | } |
| 119 | |
| 120 | static bool vnc_has_job_locked(VncState *vs) |
| 121 | { |
| 122 | VncJob *job; |
| 123 | |
| 124 | QTAILQ_FOREACH(job, &queue->jobs, next) { |
| 125 | if (job->vs == vs || !vs) { |
| 126 | return true; |
| 127 | } |
| 128 | } |
| 129 | return false; |
| 130 | } |
| 131 | |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 132 | void vnc_jobs_join(VncState *vs) |
| 133 | { |
| 134 | vnc_lock_queue(queue); |
| 135 | while (vnc_has_job_locked(vs)) { |
| 136 | qemu_cond_wait(&queue->cond, &queue->mutex); |
| 137 | } |
| 138 | vnc_unlock_queue(queue); |
Corentin Chary | 175b2a6 | 2012-03-14 07:58:47 +0100 | [diff] [blame] | 139 | vnc_jobs_consume_buffer(vs); |
| 140 | } |
| 141 | |
| 142 | void vnc_jobs_consume_buffer(VncState *vs) |
| 143 | { |
| 144 | bool flush; |
| 145 | |
| 146 | vnc_lock_output(vs); |
| 147 | if (vs->jobs_buffer.offset) { |
Daniel P. Berrange | 04d2529 | 2015-02-27 16:20:57 +0000 | [diff] [blame] | 148 | if (vs->ioc != NULL && buffer_empty(&vs->output)) { |
| 149 | if (vs->ioc_tag) { |
| 150 | g_source_remove(vs->ioc_tag); |
| 151 | } |
Klim Kireev | d49b87f | 2018-02-07 12:48:44 +0300 | [diff] [blame] | 152 | if (vs->disconnecting == FALSE) { |
| 153 | vs->ioc_tag = qio_channel_add_watch( |
| 154 | vs->ioc, G_IO_IN | G_IO_OUT, vnc_client_io, vs, NULL); |
| 155 | } |
Gerd Hoffmann | d903401 | 2015-10-30 12:10:04 +0100 | [diff] [blame] | 156 | } |
| 157 | buffer_move(&vs->output, &vs->jobs_buffer); |
Daniel P. Berrange | ada8d2e | 2017-12-18 19:12:25 +0000 | [diff] [blame] | 158 | |
| 159 | if (vs->job_update == VNC_STATE_UPDATE_FORCE) { |
| 160 | vs->force_update_offset = vs->output.offset; |
| 161 | } |
| 162 | vs->job_update = VNC_STATE_UPDATE_NONE; |
Corentin Chary | 175b2a6 | 2012-03-14 07:58:47 +0100 | [diff] [blame] | 163 | } |
Daniel P. Berrange | 04d2529 | 2015-02-27 16:20:57 +0000 | [diff] [blame] | 164 | flush = vs->ioc != NULL && vs->abort != true; |
Corentin Chary | 175b2a6 | 2012-03-14 07:58:47 +0100 | [diff] [blame] | 165 | vnc_unlock_output(vs); |
| 166 | |
| 167 | if (flush) { |
| 168 | vnc_flush(vs); |
| 169 | } |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Copy data for local use |
| 174 | */ |
| 175 | static void vnc_async_encoding_start(VncState *orig, VncState *local) |
| 176 | { |
Gerd Hoffmann | 2e0c90a | 2015-10-30 12:10:10 +0100 | [diff] [blame] | 177 | buffer_init(&local->output, "vnc-worker-output"); |
Daniel P. Berrange | 04d2529 | 2015-02-27 16:20:57 +0000 | [diff] [blame] | 178 | local->sioc = NULL; /* Don't do any network work on this thread */ |
| 179 | local->ioc = NULL; /* Don't do any network work on this thread */ |
Gerd Hoffmann | 2e0c90a | 2015-10-30 12:10:10 +0100 | [diff] [blame] | 180 | |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 181 | local->vnc_encoding = orig->vnc_encoding; |
| 182 | local->features = orig->features; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 183 | local->vd = orig->vd; |
Corentin Chary | 7d964c9 | 2011-02-04 09:05:56 +0100 | [diff] [blame] | 184 | local->lossy_rect = orig->lossy_rect; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 185 | local->write_pixels = orig->write_pixels; |
Gerd Hoffmann | 9f64916 | 2012-10-10 13:29:43 +0200 | [diff] [blame] | 186 | local->client_pf = orig->client_pf; |
| 187 | local->client_be = orig->client_be; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 188 | local->tight = orig->tight; |
| 189 | local->zlib = orig->zlib; |
| 190 | local->hextile = orig->hextile; |
Corentin Chary | 148954f | 2011-02-04 09:06:01 +0100 | [diff] [blame] | 191 | local->zrle = orig->zrle; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static void vnc_async_encoding_end(VncState *orig, VncState *local) |
| 195 | { |
Peter Wu | 0ae0b06 | 2018-08-08 00:18:30 +0200 | [diff] [blame] | 196 | buffer_free(&local->output); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 197 | orig->tight = local->tight; |
| 198 | orig->zlib = local->zlib; |
| 199 | orig->hextile = local->hextile; |
Corentin Chary | 148954f | 2011-02-04 09:06:01 +0100 | [diff] [blame] | 200 | orig->zrle = local->zrle; |
Corentin Chary | 7d964c9 | 2011-02-04 09:05:56 +0100 | [diff] [blame] | 201 | orig->lossy_rect = local->lossy_rect; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static int vnc_worker_thread_loop(VncJobQueue *queue) |
| 205 | { |
| 206 | VncJob *job; |
| 207 | VncRectEntry *entry, *tmp; |
Gerd Hoffmann | 2e0c90a | 2015-10-30 12:10:10 +0100 | [diff] [blame] | 208 | VncState vs = {}; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 209 | int n_rectangles; |
| 210 | int saved_offset; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 211 | |
| 212 | vnc_lock_queue(queue); |
| 213 | while (QTAILQ_EMPTY(&queue->jobs) && !queue->exit) { |
| 214 | qemu_cond_wait(&queue->cond, &queue->mutex); |
| 215 | } |
| 216 | /* Here job can only be NULL if queue->exit is true */ |
| 217 | job = QTAILQ_FIRST(&queue->jobs); |
| 218 | vnc_unlock_queue(queue); |
Gerd Hoffmann | f31f9c1 | 2018-05-07 12:22:54 +0200 | [diff] [blame] | 219 | assert(job->vs->magic == VNC_MAGIC); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 220 | |
| 221 | if (queue->exit) { |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | vnc_lock_output(job->vs); |
Daniel P. Berrange | 04d2529 | 2015-02-27 16:20:57 +0000 | [diff] [blame] | 226 | if (job->vs->ioc == NULL || job->vs->abort == true) { |
Corentin Chary | 175b2a6 | 2012-03-14 07:58:47 +0100 | [diff] [blame] | 227 | vnc_unlock_output(job->vs); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 228 | goto disconnected; |
| 229 | } |
Peter Lieven | c3d6899 | 2015-10-30 12:10:11 +0100 | [diff] [blame] | 230 | if (buffer_empty(&job->vs->output)) { |
| 231 | /* |
| 232 | * Looks like a NOP as it obviously moves no data. But it |
| 233 | * moves the empty buffer, so we don't have to malloc a new |
| 234 | * one for vs.output |
| 235 | */ |
| 236 | buffer_move_empty(&vs.output, &job->vs->output); |
| 237 | } |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 238 | vnc_unlock_output(job->vs); |
| 239 | |
| 240 | /* Make a local copy of vs and switch output buffers */ |
| 241 | vnc_async_encoding_start(job->vs, &vs); |
Gerd Hoffmann | f31f9c1 | 2018-05-07 12:22:54 +0200 | [diff] [blame] | 242 | vs.magic = VNC_MAGIC; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 243 | |
| 244 | /* Start sending rectangles */ |
| 245 | n_rectangles = 0; |
| 246 | vnc_write_u8(&vs, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE); |
| 247 | vnc_write_u8(&vs, 0); |
| 248 | saved_offset = vs.output.offset; |
| 249 | vnc_write_u16(&vs, 0); |
| 250 | |
| 251 | vnc_lock_display(job->vs->vd); |
| 252 | QLIST_FOREACH_SAFE(entry, &job->rectangles, next, tmp) { |
| 253 | int n; |
| 254 | |
Daniel P. Berrange | 04d2529 | 2015-02-27 16:20:57 +0000 | [diff] [blame] | 255 | if (job->vs->ioc == NULL) { |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 256 | vnc_unlock_display(job->vs->vd); |
Gonglei (Arei) | e3c1adf | 2014-01-23 13:30:57 +0000 | [diff] [blame] | 257 | /* Copy persistent encoding data */ |
| 258 | vnc_async_encoding_end(job->vs, &vs); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 259 | goto disconnected; |
| 260 | } |
| 261 | |
| 262 | n = vnc_send_framebuffer_update(&vs, entry->rect.x, entry->rect.y, |
| 263 | entry->rect.w, entry->rect.h); |
| 264 | |
| 265 | if (n >= 0) { |
| 266 | n_rectangles += n; |
| 267 | } |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 268 | g_free(entry); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 269 | } |
| 270 | vnc_unlock_display(job->vs->vd); |
| 271 | |
| 272 | /* Put n_rectangles at the beginning of the message */ |
| 273 | vs.output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF; |
| 274 | vs.output.buffer[saved_offset + 1] = n_rectangles & 0xFF; |
| 275 | |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 276 | vnc_lock_output(job->vs); |
Daniel P. Berrange | 04d2529 | 2015-02-27 16:20:57 +0000 | [diff] [blame] | 277 | if (job->vs->ioc != NULL) { |
Gerd Hoffmann | d903401 | 2015-10-30 12:10:04 +0100 | [diff] [blame] | 278 | buffer_move(&job->vs->jobs_buffer, &vs.output); |
Corentin Chary | 175b2a6 | 2012-03-14 07:58:47 +0100 | [diff] [blame] | 279 | /* Copy persistent encoding data */ |
| 280 | vnc_async_encoding_end(job->vs, &vs); |
| 281 | |
Peter Wu | 0ae0b06 | 2018-08-08 00:18:30 +0200 | [diff] [blame] | 282 | qemu_bh_schedule(job->vs->bh); |
Gonglei (Arei) | e3c1adf | 2014-01-23 13:30:57 +0000 | [diff] [blame] | 283 | } else { |
Gerd Hoffmann | d903401 | 2015-10-30 12:10:04 +0100 | [diff] [blame] | 284 | buffer_reset(&vs.output); |
Gonglei (Arei) | e3c1adf | 2014-01-23 13:30:57 +0000 | [diff] [blame] | 285 | /* Copy persistent encoding data */ |
| 286 | vnc_async_encoding_end(job->vs, &vs); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 287 | } |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 288 | vnc_unlock_output(job->vs); |
| 289 | |
Corentin Chary | 175b2a6 | 2012-03-14 07:58:47 +0100 | [diff] [blame] | 290 | disconnected: |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 291 | vnc_lock_queue(queue); |
| 292 | QTAILQ_REMOVE(&queue->jobs, job, next); |
| 293 | vnc_unlock_queue(queue); |
| 294 | qemu_cond_broadcast(&queue->cond); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 295 | g_free(job); |
Gerd Hoffmann | f31f9c1 | 2018-05-07 12:22:54 +0200 | [diff] [blame] | 296 | vs.magic = 0; |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | static VncJobQueue *vnc_queue_init(void) |
| 301 | { |
Markus Armbruster | fedf0d3 | 2015-11-03 17:12:03 +0100 | [diff] [blame] | 302 | VncJobQueue *queue = g_new0(VncJobQueue, 1); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 303 | |
| 304 | qemu_cond_init(&queue->cond); |
| 305 | qemu_mutex_init(&queue->mutex); |
| 306 | QTAILQ_INIT(&queue->jobs); |
| 307 | return queue; |
| 308 | } |
| 309 | |
| 310 | static void vnc_queue_clear(VncJobQueue *q) |
| 311 | { |
| 312 | qemu_cond_destroy(&queue->cond); |
| 313 | qemu_mutex_destroy(&queue->mutex); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 314 | g_free(q); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 315 | queue = NULL; /* Unset global queue */ |
| 316 | } |
| 317 | |
| 318 | static void *vnc_worker_thread(void *arg) |
| 319 | { |
| 320 | VncJobQueue *queue = arg; |
| 321 | |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 322 | qemu_thread_get_self(&queue->thread); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 323 | |
| 324 | while (!vnc_worker_thread_loop(queue)) ; |
| 325 | vnc_queue_clear(queue); |
| 326 | return NULL; |
| 327 | } |
| 328 | |
Blue Swirl | 71a8cde | 2012-10-28 11:04:48 +0000 | [diff] [blame] | 329 | static bool vnc_worker_thread_running(void) |
| 330 | { |
| 331 | return queue; /* Check global queue */ |
| 332 | } |
| 333 | |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 334 | void vnc_start_worker_thread(void) |
| 335 | { |
| 336 | VncJobQueue *q; |
| 337 | |
| 338 | if (vnc_worker_thread_running()) |
| 339 | return ; |
| 340 | |
| 341 | q = vnc_queue_init(); |
Dr. David Alan Gilbert | 4900116 | 2014-01-30 10:20:32 +0000 | [diff] [blame] | 342 | qemu_thread_create(&q->thread, "vnc_worker", vnc_worker_thread, q, |
| 343 | QEMU_THREAD_DETACHED); |
Corentin Chary | bd023f9 | 2010-07-07 20:58:02 +0200 | [diff] [blame] | 344 | queue = q; /* Set global queue */ |
| 345 | } |