[Spice-devel] [PATCH spice-server v2 03/12] Save running property in QXLState

Frediano Ziglio fziglio at redhat.com
Tue Mar 26 19:10:29 UTC 2019


From: Jonathon Jongsma <jjongsma at redhat.com>

This is a preparatory patch that states the running property in QXLState
and provides accessor functions that allows us to check whether the QXL
device is running from different threads.

Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/red-qxl.c    | 13 +++++++++++++
 server/red-qxl.h    |  3 +++
 server/red-worker.c | 23 +++++++++++------------
 server/red-worker.h |  1 +
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/server/red-qxl.c b/server/red-qxl.c
index 8274be56..e3fbf7b7 100644
--- a/server/red-qxl.c
+++ b/server/red-qxl.c
@@ -59,6 +59,8 @@ struct QXLState {
     uint32_t device_display_ids[MAX_MONITORS_COUNT];
     size_t monitors_count;  // length of ^^^
 
+    bool running;
+
     pthread_mutex_t scanout_mutex;
     SpiceMsgDisplayGlScanoutUnix scanout;
     uint64_t gl_draw_cookie;
@@ -66,6 +68,17 @@ struct QXLState {
 
 #define GL_DRAW_COOKIE_INVALID (~((uint64_t) 0))
 
+bool red_qxl_is_running(QXLInstance *qxl)
+{
+    return qxl->st->running;
+}
+
+/* used by RedWorker */
+void red_qxl_set_running(QXLInstance *qxl, bool running)
+{
+    qxl->st->running = running;
+}
+
 int red_qxl_check_qxl_version(QXLInstance *qxl, int major, int minor)
 {
     int qxl_major = qxl_get_interface(qxl)->base.major_version;
diff --git a/server/red-qxl.h b/server/red-qxl.h
index 94753948..521f3659 100644
--- a/server/red-qxl.h
+++ b/server/red-qxl.h
@@ -44,6 +44,9 @@ const char* red_qxl_get_device_address(const QXLInstance *qxl);
 const uint32_t* red_qxl_get_device_display_ids(const QXLInstance *qxl);
 size_t red_qxl_get_monitors_count(const QXLInstance *qxl);
 
+/* check if QXL is running, should be used inside the worker thread */
+bool red_qxl_is_running(QXLInstance *qxl);
+
 /* Wrappers around QXLInterface vfuncs */
 void red_qxl_get_init_info(QXLInstance *qxl, QXLDevInitInfo *info);
 int red_qxl_get_command(QXLInstance *qxl, struct QXLCommandExt *cmd);
diff --git a/server/red-worker.c b/server/red-worker.c
index 27fe04cc..b80fefab 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -63,7 +63,6 @@ struct RedWorker {
     pthread_t thread;
     QXLInstance *qxl;
     SpiceWatch *dispatch_watch;
-    int running;
     SpiceCoreInterfaceInternal core;
 
     unsigned int event_timeout;
@@ -115,7 +114,7 @@ static int red_process_cursor(RedWorker *worker, int *ring_is_empty)
     QXLCommandExt ext_cmd;
     int n = 0;
 
-    if (!worker->running) {
+    if (!red_qxl_is_running(worker->qxl)) {
         *ring_is_empty = TRUE;
         return n;
     }
@@ -173,7 +172,7 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
     int n = 0;
     uint64_t start = spice_get_monotonic_time_ns();
 
-    if (!worker->running) {
+    if (!red_qxl_is_running(worker->qxl)) {
         *ring_is_empty = TRUE;
         return n;
     }
@@ -378,7 +377,7 @@ static void guest_set_client_capabilities(RedWorker *worker)
 #define CLEAR_CAP(a,c)                                                  \
         ((a)[(c) / 8] &= ~(1 << ((c) % 8)))
 
-    if (!worker->running) {
+    if (!red_qxl_is_running(worker->qxl)) {
         return;
     }
     if ((worker->display_channel == NULL) ||
@@ -406,7 +405,7 @@ static void handle_dev_update_async(void *opaque, void *payload)
     QXLRect *qxl_dirty_rects = NULL;
     uint32_t num_dirty_rects = 0;
 
-    spice_return_if_fail(worker->running);
+    spice_return_if_fail(red_qxl_is_running(worker->qxl));
     spice_return_if_fail(qxl_get_interface(worker->qxl)->update_area_complete);
 
     flush_display_commands(worker);
@@ -426,7 +425,7 @@ static void handle_dev_update(void *opaque, void *payload)
     RedWorkerMessageUpdate *msg = payload;
     QXLRect *qxl_dirty_rects = msg->qxl_dirty_rects;
 
-    spice_return_if_fail(worker->running);
+    spice_return_if_fail(red_qxl_is_running(worker->qxl));
 
     flush_display_commands(worker);
     display_channel_update(worker->display_channel,
@@ -586,9 +585,9 @@ static void handle_dev_stop(void *opaque, void *payload)
     RedWorker *worker = opaque;
 
     spice_debug("stop");
-    spice_assert(worker->running);
+    spice_assert(red_qxl_is_running(worker->qxl));
 
-    worker->running = FALSE;
+    red_qxl_set_running(worker->qxl, false);
 
     display_channel_free_glz_drawables(worker->display_channel);
     display_channel_flush_all_surfaces(worker->display_channel);
@@ -606,7 +605,7 @@ static void handle_dev_start(void *opaque, void *payload)
 {
     RedWorker *worker = opaque;
 
-    spice_assert(!worker->running);
+    spice_assert(!red_qxl_is_running(worker->qxl));
     if (worker->cursor_channel) {
         CommonGraphicsChannel *common = COMMON_GRAPHICS_CHANNEL(worker->cursor_channel);
         common_graphics_channel_set_during_target_migrate(common, FALSE);
@@ -616,7 +615,7 @@ static void handle_dev_start(void *opaque, void *payload)
         common_graphics_channel_set_during_target_migrate(common, FALSE);
         display_channel_wait_for_migrate_data(worker->display_channel);
     }
-    worker->running = TRUE;
+    red_qxl_set_running(worker->qxl, true);
     worker->event_timeout = 0;
     guest_set_client_capabilities(worker);
 }
@@ -637,7 +636,7 @@ static void handle_dev_oom(void *opaque, void *payload)
     RedChannel *display_red_channel = RED_CHANNEL(display);
     int ring_is_empty;
 
-    spice_return_if_fail(worker->running);
+    spice_return_if_fail(red_qxl_is_running(worker->qxl));
     // streams? but without streams also leak
     display_channel_debug_oom(display, "OOM1");
     while (red_process_display(worker, &ring_is_empty)) {
@@ -1153,7 +1152,7 @@ static gboolean worker_source_check(GSource *source)
     RedWorkerSource *wsource = SPICE_CONTAINEROF(source, RedWorkerSource, source);
     RedWorker *worker = wsource->worker;
 
-    return worker->running /* TODO && worker->pending_process */;
+    return red_qxl_is_running(worker->qxl) /* TODO && worker->pending_process */;
 }
 
 static gboolean worker_source_dispatch(GSource *source, GSourceFunc callback,
diff --git a/server/red-worker.h b/server/red-worker.h
index 3d2841ba..54ab4da8 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -35,6 +35,7 @@ void red_worker_free(RedWorker *worker);
 struct Dispatcher *red_qxl_get_dispatcher(QXLInstance *qxl);
 void red_qxl_destroy_primary_surface_complete(QXLState *qxl_state);
 void red_qxl_create_primary_surface_complete(QXLState *qxl_state, const QXLDevSurfaceCreate* surface);
+void red_qxl_set_running(QXLInstance *qxl, bool running);
 
 typedef uint32_t RedWorkerMessage;
 
-- 
2.20.1



More information about the Spice-devel mailing list