[Spice-devel] [PATCH spice-server 02/20] red_worker: add RED_WORKER_MESSAGE_CLOSE_WORKER message
Pavel Grunt
pgrunt at redhat.com
Fri Nov 25 14:23:02 UTC 2016
maybe red-worker: Add way for closing main thread
..and it would be nice to have some description of what is actually
going on with the new message - when it should be sent, how is handled
etc
On Thu, 2016-11-24 at 17:38 +0000, Frediano Ziglio wrote:
> Allows to close main thread.
> 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)
More information about the Spice-devel
mailing list