[Spice-devel] [PATCH 4/7] add red_dispatcher_destroy function
Frediano Ziglio
fziglio at redhat.com
Wed Oct 14 08:37:33 PDT 2015
Allows to destroy a RedDispatcher object
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/red_dispatcher.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
server/red_dispatcher.h | 1 +
2 files changed, 55 insertions(+)
diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index 660dad8..16e4cc3 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -67,6 +67,8 @@ struct RedDispatcher {
pthread_mutex_t async_lock;
QXLDevSurfaceCreate surface_create;
unsigned int max_monitors;
+ RedChannel *display_channel;
+ RedChannel *cursor_channel;
};
extern uint32_t streaming_video;
@@ -1157,6 +1159,7 @@ void red_dispatcher_init(QXLInstance *qxl)
red_channel_set_cap(display_channel, SPICE_DISPLAY_CAP_PREF_COMPRESSION);
red_channel_set_cap(display_channel, SPICE_DISPLAY_CAP_STREAM_REPORT);
reds_register_channel(display_channel);
+ red_dispatcher->display_channel = display_channel;
}
cursor_channel = red_dispatcher_cursor_channel_create(red_dispatcher);
@@ -1168,6 +1171,7 @@ void red_dispatcher_init(QXLInstance *qxl)
red_channel_register_client_cbs(cursor_channel, &client_cbs);
red_channel_set_data(cursor_channel, red_dispatcher);
reds_register_channel(cursor_channel);
+ red_dispatcher->cursor_channel = cursor_channel;
}
qxl->st->dispatcher = red_dispatcher;
@@ -1178,6 +1182,56 @@ void red_dispatcher_init(QXLInstance *qxl)
qxl->st->qif->set_compression_level(qxl, calc_compression_level());
}
+void red_dispatcher_destroy(QXLInstance *qxl)
+{
+ RedDispatcher *red_dispatcher;
+ RedWorkerMessageClose message;
+ RingItem *item, *next;
+
+ spice_return_if_fail(qxl->st != NULL && qxl->st->dispatcher != NULL);
+
+ // TODO implement it
+ // qxl->st->qif->detach_worker(qxl, &red_dispatcher->base);
+
+ red_dispatcher = qxl->st->dispatcher;
+
+ RedDispatcher **curr = &dispatchers;
+ while (*curr) {
+ if (*curr == red_dispatcher) {
+ *curr = red_dispatcher->next;
+ break;
+ }
+ curr = &(*curr)->next;
+ }
+
+ /* deregister channels (display and cursor) */
+ if (red_dispatcher->cursor_channel)
+ reds_unregister_channel(red_dispatcher->cursor_channel);
+ if (red_dispatcher->display_channel)
+ reds_unregister_channel(red_dispatcher->display_channel);
+
+ /* send message to close thread */
+ dispatcher_send_message(&red_dispatcher->dispatcher,
+ RED_WORKER_MESSAGE_CLOSE_WORKER,
+ &message);
+ pthread_join(red_dispatcher->worker_thread, NULL);
+
+ dispatcher_destroy(&red_dispatcher->dispatcher);
+
+ /* destroy Ring async_commands */
+ RING_FOREACH_SAFE(item, next, &red_dispatcher->async_commands) {
+ free(item);
+ }
+
+ pthread_mutex_destroy(&red_dispatcher->async_lock);
+
+ qxl->st->dispatcher = NULL;
+ free(red_dispatcher);
+
+ num_active_workers = 0;
+}
+
+
struct Dispatcher *red_dispatcher_get_dispatcher(RedDispatcher *red_dispatcher)
{
return &red_dispatcher->dispatcher;
diff --git a/server/red_dispatcher.h b/server/red_dispatcher.h
index 3461ba4..a50ae15 100644
--- a/server/red_dispatcher.h
+++ b/server/red_dispatcher.h
@@ -25,6 +25,7 @@ struct RedDispatcher;
typedef struct AsyncCommand AsyncCommand;
void red_dispatcher_init(QXLInstance *qxl);
+void red_dispatcher_destroy(QXLInstance *qxl);
void red_dispatcher_set_mm_time(uint32_t);
void red_dispatcher_on_ic_change(void);
--
2.4.3
More information about the Spice-devel
mailing list