[Spice-devel] [PATCH v2 01/19] red_worker: add RED_WORKER_MESSAGE_CLOSE_WORKER message
Frediano Ziglio
fziglio at redhat.com
Fri Nov 25 14:52:31 UTC 2016
Allows to close worker thread.
This will be used to destroy cleanly CursorChannel and
DisplayChannel.
CursorChannel and DisplayChannel are run in a different
thread. However deregistration of channels and different
steps of destruction should be done in the same thread
so this make possible to join again the 2 threads to
avoid race conditions.
For the moment there is no correct cleanup.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/red-qxl.h | 6 ++++++
server/red-worker.c | 18 ++++++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/server/red-qxl.h b/server/red-qxl.h
index 0ff2475..65357b1 100644
--- a/server/red-qxl.h
+++ b/server/red-qxl.h
@@ -116,6 +116,9 @@ enum {
RED_WORKER_MESSAGE_GL_DRAW_ASYNC,
RED_WORKER_MESSAGE_SET_VIDEO_CODECS,
+ /* close worker thread */
+ RED_WORKER_MESSAGE_CLOSE_WORKER,
+
RED_WORKER_MESSAGE_COUNT // LAST
};
@@ -291,6 +294,9 @@ typedef struct RedWorkerMessageDriverUnload {
typedef struct RedWorkerMessageGlScanout {
} RedWorkerMessageGlScanout;
+typedef struct RedWorkerMessageClose {
+} RedWorkerMessageClose;
+
enum {
RED_DISPATCHER_PENDING_WAKEUP,
RED_DISPATCHER_PENDING_OOM,
diff --git a/server/red-worker.c b/server/red-worker.c
index f8c135f..d699bd6 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -85,6 +85,7 @@ struct RedWorker {
int driver_cap_monitors_config;
RedRecord *record;
+ GMainLoop *loop;
};
static int display_is_connected(RedWorker *worker)
@@ -971,6 +972,12 @@ void handle_dev_gl_draw_async(void *opaque, void *payload)
display_channel_gl_draw(worker->display_channel, draw);
}
+static void handle_dev_close(void *opaque, void *payload)
+{
+ RedWorker *worker = opaque;
+ g_main_loop_quit(worker->loop);
+}
+
static int loadvm_command(RedWorker *worker, QXLCommandExt *ext)
{
RedCursorCmd *cursor_cmd;
@@ -1222,6 +1229,11 @@ static void register_callbacks(Dispatcher *dispatcher)
handle_dev_gl_draw_async,
sizeof(SpiceMsgDisplayGlDraw),
DISPATCHER_NONE);
+ dispatcher_register_handler(dispatcher,
+ RED_WORKER_MESSAGE_CLOSE_WORKER,
+ handle_dev_close,
+ sizeof(RedWorkerMessageClose),
+ DISPATCHER_NONE);
}
@@ -1381,7 +1393,7 @@ RedWorker* red_worker_new(QXLInstance *qxl,
return worker;
}
-SPICE_GNUC_NORETURN static void *red_worker_main(void *arg)
+static void *red_worker_main(void *arg)
{
RedWorker *worker = arg;
@@ -1393,11 +1405,13 @@ SPICE_GNUC_NORETURN static void *red_worker_main(void *arg)
red_channel_reset_thread_id(RED_CHANNEL(worker->display_channel));
GMainLoop *loop = g_main_loop_new(worker->core.main_context, FALSE);
+ worker->loop = loop;
g_main_loop_run(loop);
g_main_loop_unref(loop);
+ worker->loop = NULL;
/* FIXME: free worker, and join threads */
- exit(0);
+ return NULL;
}
bool red_worker_run(RedWorker *worker)
--
git-series 0.9.1
More information about the Spice-devel
mailing list