[Spice-devel] [PATCH v2 6/6] server/red_worker: use dispatcher_register_async_callback

Alon Levy alevy at redhat.com
Mon Nov 7 03:44:46 PST 2011


---
 server/red_dispatcher.c |   14 +++---
 server/red_dispatcher.h |   18 +++++---
 server/red_worker.c     |   94 ++++++++++++++++++++++++-----------------------
 3 files changed, 66 insertions(+), 60 deletions(-)

diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index eaa0164..17b469e 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -309,7 +309,7 @@ static void red_dispatcher_update_area_async(RedDispatcher *dispatcher,
     RedWorkerMessage message = RED_WORKER_MESSAGE_UPDATE_ASYNC;
     RedWorkerMessageUpdateAsync payload;
 
-    payload.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
     payload.surface_id = surface_id;
     payload.qxl_area = *qxl_area;
     payload.clear_dirty_region = clear_dirty_region;
@@ -346,7 +346,7 @@ static void red_dispatcher_add_memslot_async(RedDispatcher *dispatcher, QXLDevMe
     RedWorkerMessageAddMemslotAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC;
 
-    payload.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
     payload.mem_slot = *mem_slot;
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
@@ -385,7 +385,7 @@ static void red_dispatcher_destroy_surfaces_async(RedDispatcher *dispatcher, uin
     RedWorkerMessageDestroySurfacesAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC;
 
-    payload.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
 
@@ -418,7 +418,7 @@ red_dispatcher_destroy_primary_surface_async(RedDispatcher *dispatcher,
     RedWorkerMessageDestroyPrimarySurfaceAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC;
 
-    payload.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
     payload.surface_id = surface_id;
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
@@ -460,7 +460,7 @@ red_dispatcher_create_primary_surface_async(RedDispatcher *dispatcher, uint32_t
     RedWorkerMessage message = RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC;
 
     dispatcher->surface_create = *surface;
-    payload.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
     payload.surface_id = surface_id;
     payload.surface = *surface;
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
@@ -544,7 +544,7 @@ static void red_dispatcher_destroy_surface_wait_async(RedDispatcher *dispatcher,
     RedWorkerMessageDestroySurfaceWaitAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC;
 
-    payload.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
     payload.surface_id = surface_id;
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
@@ -634,7 +634,7 @@ static void red_dispatcher_flush_surfaces_async(RedDispatcher *dispatcher, uint6
     RedWorkerMessageFlushSurfacesAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC;
 
-    payload.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
 
diff --git a/server/red_dispatcher.h b/server/red_dispatcher.h
index 59edb44..7417aac 100644
--- a/server/red_dispatcher.h
+++ b/server/red_dispatcher.h
@@ -70,8 +70,12 @@ typedef struct RedWorkerMessageUpdate {
     uint32_t clear_dirty_region;
 } RedWorkerMessageUpdate;
 
-typedef struct RedWorkerMessageUpdateAsync {
+typedef struct RedWorkerMessageAsync {
     AsyncCommand *cmd;
+} RedWorkerMessageAsync;
+
+typedef struct RedWorkerMessageUpdateAsync {
+    RedWorkerMessageAsync base;
     uint32_t surface_id;
     QXLRect qxl_area;
     uint32_t clear_dirty_region;
@@ -82,7 +86,7 @@ typedef struct RedWorkerMessageAddMemslot {
 } RedWorkerMessageAddMemslot;
 
 typedef struct RedWorkerMessageAddMemslotAsync {
-    AsyncCommand *cmd;
+    RedWorkerMessageAsync base;
     QXLDevMemSlot mem_slot;
 } RedWorkerMessageAddMemslotAsync;
 
@@ -95,7 +99,7 @@ typedef struct RedWorkerMessageDestroySurfaces {
 } RedWorkerMessageDestroySurfaces;
 
 typedef struct RedWorkerMessageDestroySurfacesAsync {
-    AsyncCommand *cmd;
+    RedWorkerMessageAsync base;
 } RedWorkerMessageDestroySurfacesAsync;
 
 
@@ -104,12 +108,12 @@ typedef struct RedWorkerMessageDestroyPrimarySurface {
 } RedWorkerMessageDestroyPrimarySurface;
 
 typedef struct RedWorkerMessageDestroyPrimarySurfaceAsync {
-    AsyncCommand *cmd;
+    RedWorkerMessageAsync base;
     uint32_t surface_id;
 } RedWorkerMessageDestroyPrimarySurfaceAsync;
 
 typedef struct RedWorkerMessageCreatePrimarySurfaceAsync {
-    AsyncCommand *cmd;
+    RedWorkerMessageAsync base;
     uint32_t surface_id;
     QXLDevSurfaceCreate surface;
 } RedWorkerMessageCreatePrimarySurfaceAsync;
@@ -135,7 +139,7 @@ typedef struct RedWorkerMessageStart {
 } RedWorkerMessageStart;
 
 typedef struct RedWorkerMessageFlushSurfacesAsync {
-    AsyncCommand *cmd;
+    RedWorkerMessageAsync base;
 } RedWorkerMessageFlushSurfacesAsync;
 
 typedef struct RedWorkerMessageStop {
@@ -170,7 +174,7 @@ typedef struct RedWorkerMessageDestroySurfaceWait {
 } RedWorkerMessageDestroySurfaceWait;
 
 typedef struct RedWorkerMessageDestroySurfaceWaitAsync {
-    AsyncCommand *cmd;
+    RedWorkerMessageAsync base;
     uint32_t surface_id;
 } RedWorkerMessageDestroySurfaceWaitAsync;
 
diff --git a/server/red_worker.c b/server/red_worker.c
index 0bb5b0c..287ca89 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -10125,12 +10125,12 @@ void handle_dev_update_async(void *opaque, void *payload)
     validate_surface(worker, surface_id);
     red_update_area(worker, &rect, surface_id);
     if (!worker->qxl->st->qif->update_area_complete) {
-        goto complete;
+        return;
     }
     surface = &worker->surfaces[surface_id];
     num_dirty_rects = pixman_region32_n_rects(&surface->draw_dirty_region);
     if (num_dirty_rects == 0) {
-        goto complete;
+        return;
     }
     qxl_dirty_rects = spice_new0(QXLRect, num_dirty_rects);
     surface_dirty_region_to_rects(surface, qxl_dirty_rects, num_dirty_rects,
@@ -10138,9 +10138,6 @@ void handle_dev_update_async(void *opaque, void *payload)
     worker->qxl->st->qif->update_area_complete(worker->qxl, surface_id,
                                           qxl_dirty_rects, num_dirty_rects);
     free(qxl_dirty_rects);
-
-complete:
-    red_dispatcher_async_complete(worker->red_dispatcher, msg->cmd);
 }
 
 void handle_dev_update(void *opaque, void *payload)
@@ -10365,7 +10362,6 @@ void handle_dev_destroy_primary_surface_async(void *opaque, void *payload)
     uint32_t surface_id = msg->surface_id;
 
     dev_destroy_primary_surface(worker, surface_id);
-    red_dispatcher_async_complete(worker->red_dispatcher, msg->cmd);
 }
 
 static void flush_all_surfaces(RedWorker *worker)
@@ -10396,11 +10392,9 @@ void handle_dev_flush_surfaces(void *opaque, void *payload)
 
 void handle_dev_flush_surfaces_async(void *opaque, void *payload)
 {
-    RedWorkerMessageFlushSurfacesAsync *msg = payload;
     RedWorker *worker = opaque;
 
     dev_flush_surfaces(worker);
-    red_dispatcher_async_complete(worker->red_dispatcher, msg->cmd);
 }
 
 void handle_dev_stop(void *opaque, void *payload)
@@ -10491,16 +10485,13 @@ void handle_dev_destroy_surface_wait_async(void *opaque, void *payload)
     RedWorker *worker = opaque;
 
     dev_destroy_surface_wait(worker, msg->surface_id);
-    red_dispatcher_async_complete(worker->red_dispatcher, msg->cmd);
 }
 
 void handle_dev_destroy_surfaces_async(void *opaque, void *payload)
 {
-    RedWorkerMessageDestroySurfacesAsync *msg = payload;
     RedWorker *worker = opaque;
 
     dev_destroy_surfaces(worker);
-    red_dispatcher_async_complete(worker->red_dispatcher, msg->cmd);
 }
 
 void handle_dev_create_primary_surface_async(void *opaque, void *payload)
@@ -10509,7 +10500,6 @@ void handle_dev_create_primary_surface_async(void *opaque, void *payload)
     RedWorker *worker = opaque;
 
     dev_create_primary_surface(worker, msg->surface_id, msg->surface);
-    red_dispatcher_async_complete(worker->red_dispatcher, msg->cmd);
 }
 
 /* exception for Dispatcher, data going from red_worker to main thread,
@@ -10685,7 +10675,6 @@ void handle_dev_add_memslot_async(void *opaque, void *payload)
     RedWorker *worker = opaque;
 
     dev_add_memslot(worker, msg->mem_slot);
-    red_dispatcher_async_complete(worker->red_dispatcher, msg->cmd);
 }
 
 void handle_dev_reset_memslots(void *opaque, void *payload)
@@ -10727,173 +10716,186 @@ void handle_dev_loadvm_commands(void *opaque, void *payload)
     }
 }
 
+static void worker_handle_dispatcher_async_done(void *opaque,
+                                                uint32_t message_type,
+                                                void *payload)
+{
+    RedWorker *worker = opaque;
+    RedWorkerMessageAsync *msg_async = payload;
+
+    red_printf_debug(2, "WORKER", "");
+    red_dispatcher_async_complete(worker->red_dispatcher, msg_async->cmd);
+}
+
 static void register_callbacks(Dispatcher *dispatcher)
 {
+    dispatcher_register_async_callback(dispatcher,
+                                       worker_handle_dispatcher_async_done);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DISPLAY_CONNECT,
                                 handle_dev_display_connect,
                                 sizeof(RedWorkerMessageDisplayConnect),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
                                 handle_dev_display_disconnect,
                                 sizeof(RedWorkerMessageDisplayDisconnect),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
                                 handle_dev_display_migrate,
                                 sizeof(RedWorkerMessageDisplayMigrate),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_CURSOR_CONNECT,
                                 handle_dev_cursor_connect,
                                 sizeof(RedWorkerMessageCursorConnect),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
                                 handle_dev_cursor_disconnect,
                                 sizeof(RedWorkerMessageCursorDisconnect),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_CURSOR_MIGRATE,
                                 handle_dev_cursor_migrate,
                                 sizeof(RedWorkerMessageCursorMigrate),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_UPDATE,
                                 handle_dev_update,
                                 sizeof(RedWorkerMessageUpdate),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_UPDATE_ASYNC,
                                 handle_dev_update_async,
                                 sizeof(RedWorkerMessageUpdateAsync),
-                                0);
+                                DISPATCHER_ASYNC);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_ADD_MEMSLOT,
                                 handle_dev_add_memslot,
                                 sizeof(RedWorkerMessageAddMemslot),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC,
                                 handle_dev_add_memslot_async,
                                 sizeof(RedWorkerMessageAddMemslotAsync),
-                                0);
+                                DISPATCHER_ASYNC);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DEL_MEMSLOT,
                                 handle_dev_del_memslot,
                                 sizeof(RedWorkerMessageDelMemslot),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DESTROY_SURFACES,
                                 handle_dev_destroy_surfaces,
                                 sizeof(RedWorkerMessageDestroySurfaces),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC,
                                 handle_dev_destroy_surfaces_async,
                                 sizeof(RedWorkerMessageDestroySurfacesAsync),
-                                0);
+                                DISPATCHER_ASYNC);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
                                 handle_dev_destroy_primary_surface,
                                 sizeof(RedWorkerMessageDestroyPrimarySurface),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC,
                                 handle_dev_destroy_primary_surface_async,
                                 sizeof(RedWorkerMessageDestroyPrimarySurfaceAsync),
-                                0);
+                                DISPATCHER_ASYNC);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC,
                                 handle_dev_create_primary_surface_async,
                                 sizeof(RedWorkerMessageCreatePrimarySurfaceAsync),
-                                0);
+                                DISPATCHER_ASYNC);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
                                 handle_dev_create_primary_surface,
                                 sizeof(RedWorkerMessageCreatePrimarySurface),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
                                 handle_dev_reset_image_cache,
                                 sizeof(RedWorkerMessageResetImageCache),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_RESET_CURSOR,
                                 handle_dev_reset_cursor,
                                 sizeof(RedWorkerMessageResetCursor),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_WAKEUP,
                                 handle_dev_wakeup,
                                 sizeof(RedWorkerMessageWakeup),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_OOM,
                                 handle_dev_oom,
                                 sizeof(RedWorkerMessageOom),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_START,
                                 handle_dev_start,
                                 sizeof(RedWorkerMessageStart),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC,
                                 handle_dev_flush_surfaces_async,
                                 sizeof(RedWorkerMessageFlushSurfacesAsync),
-                                0);
+                                DISPATCHER_ASYNC);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_STOP,
                                 handle_dev_stop,
                                 sizeof(RedWorkerMessageStop),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_LOADVM_COMMANDS,
                                 handle_dev_loadvm_commands,
                                 sizeof(RedWorkerMessageLoadvmCommands),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_SET_COMPRESSION,
                                 handle_dev_set_compression,
                                 sizeof(RedWorkerMessageSetCompression),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
                                 handle_dev_set_streaming_video,
                                 sizeof(RedWorkerMessageSetStreamingVideo),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_SET_MOUSE_MODE,
                                 handle_dev_set_mouse_mode,
                                 sizeof(RedWorkerMessageSetMouseMode),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DISPLAY_CHANNEL_CREATE,
                                 handle_dev_display_channel_create,
                                 sizeof(RedWorkerMessageDisplayChannelCreate),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_CURSOR_CHANNEL_CREATE,
                                 handle_dev_cursor_channel_create,
                                 sizeof(RedWorkerMessageCursorChannelCreate),
-                                0);
+                                DISPATCHER_NONE);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
                                 handle_dev_destroy_surface_wait,
                                 sizeof(RedWorkerMessageDestroySurfaceWait),
-                                1);
+                                DISPATCHER_ACK);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC,
                                 handle_dev_destroy_surface_wait_async,
                                 sizeof(RedWorkerMessageDestroySurfaceWaitAsync),
-                                0);
+                                DISPATCHER_ASYNC);
     dispatcher_register_handler(dispatcher,
                                 RED_WORKER_MESSAGE_RESET_MEMSLOTS,
                                 handle_dev_reset_memslots,
                                 sizeof(RedWorkerMessageResetMemslots),
-                                0);
+                                DISPATCHER_NONE);
 }
 
 
-- 
1.7.7.1



More information about the Spice-devel mailing list