[Spice-devel] [PATCH v2] server: async: add cookie

Alon Levy alevy at redhat.com
Wed Jul 6 10:37:18 PDT 2011


---
 server/red_dispatcher.c |   64 ++++++++++++++++++++++++++++++-----------------
 server/red_worker.c     |    4 ++-
 server/spice.h          |   18 ++++++------
 3 files changed, 53 insertions(+), 33 deletions(-)

diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index 477dede..6cc6abb 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -212,7 +212,7 @@ static void update_client_mouse_allowed(void)
 static void qxl_worker_update_area_helper(QXLWorker *qxl_worker, uint32_t surface_id,
                                    QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
                                    uint32_t num_dirty_rects, uint32_t clear_dirty_region,
-                                   int async)
+                                   int async, uint64_t cookie)
 {
     RedDispatcher *dispatcher = (RedDispatcher *)qxl_worker;
     RedWorkerMessage message;
@@ -223,6 +223,9 @@ static void qxl_worker_update_area_helper(QXLWorker *qxl_worker, uint32_t surfac
          message = RED_WORKER_MESSAGE_UPDATE;
     }
     write_message(dispatcher->channel, &message);
+    if (async) {
+        send_data(dispatcher->channel, &cookie, sizeof(cookie));
+    }
     send_data(dispatcher->channel, &surface_id, sizeof(uint32_t));
     send_data(dispatcher->channel, &qxl_area, sizeof(QXLRect *));
     send_data(dispatcher->channel, &qxl_dirty_rects, sizeof(QXLRect *));
@@ -240,15 +243,15 @@ static void qxl_worker_update_area(QXLWorker *qxl_worker, uint32_t surface_id,
                                    uint32_t num_dirty_rects, uint32_t clear_dirty_region)
 {
     qxl_worker_update_area_helper(qxl_worker, surface_id, qxl_area, qxl_dirty_rects, num_dirty_rects,
-        clear_dirty_region, 0);
+        clear_dirty_region, 0, 0);
 }
 
 static void qxl_worker_update_area_async(QXLWorker *qxl_worker, uint32_t surface_id,
                                    QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
-                                   uint32_t num_dirty_rects, uint32_t clear_dirty_region)
+                                   uint32_t num_dirty_rects, uint32_t clear_dirty_region, uint64_t cookie)
 {
     qxl_worker_update_area_helper(qxl_worker, surface_id, qxl_area, qxl_dirty_rects, num_dirty_rects,
-        clear_dirty_region, 1);
+        clear_dirty_region, 1, cookie);
 }
 
 
@@ -263,12 +266,13 @@ static void qxl_worker_add_memslot(QXLWorker *qxl_worker, QXLDevMemSlot *mem_slo
     ASSERT(message == RED_WORKER_MESSAGE_READY);
 }
 
-static void qxl_worker_add_memslot_async(QXLWorker *qxl_worker, QXLDevMemSlot *mem_slot)
+static void qxl_worker_add_memslot_async(QXLWorker *qxl_worker, QXLDevMemSlot *mem_slot, uint64_t cookie)
 {
     RedDispatcher *dispatcher = (RedDispatcher *)qxl_worker;
     RedWorkerMessage message = RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC;
 
     write_message(dispatcher->channel, &message);
+    send_data(dispatcher->channel, &cookie, sizeof(cookie));
     send_data(dispatcher->channel, mem_slot, sizeof(QXLDevMemSlot));
 }
 
@@ -292,16 +296,17 @@ static void qxl_worker_destroy_surfaces(QXLWorker *qxl_worker)
     ASSERT(message == RED_WORKER_MESSAGE_READY);
 }
 
-static void qxl_worker_destroy_surfaces_async(QXLWorker *qxl_worker)
+static void qxl_worker_destroy_surfaces_async(QXLWorker *qxl_worker, uint64_t cookie)
 {
     RedDispatcher *dispatcher = (RedDispatcher *)qxl_worker;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC;
 
     write_message(dispatcher->channel, &message);
+    send_data(dispatcher->channel, &cookie, sizeof(cookie));
 }
 
 static void qxl_worker_destroy_primary_surface_helper(QXLWorker *qxl_worker, uint32_t surface_id,
-                                              int async)
+                                              int async, uint64_t cookie)
 {
     RedDispatcher *dispatcher = (RedDispatcher *)qxl_worker;
     RedWorkerMessage message;
@@ -313,6 +318,9 @@ static void qxl_worker_destroy_primary_surface_helper(QXLWorker *qxl_worker, uin
     }
 
     write_message(dispatcher->channel, &message);
+    if (async) {
+        send_data(dispatcher->channel, &cookie, sizeof(cookie));
+    }
     send_data(dispatcher->channel, &surface_id, sizeof(uint32_t));
     if (!async) {
         read_message(dispatcher->channel, &message);
@@ -330,16 +338,16 @@ static void qxl_worker_destroy_primary_surface_helper(QXLWorker *qxl_worker, uin
 
 static void qxl_worker_destroy_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id)
 {
-    qxl_worker_destroy_primary_surface_helper(qxl_worker, surface_id, 0);
+    qxl_worker_destroy_primary_surface_helper(qxl_worker, surface_id, 0, 0);
 }
 
-static void qxl_worker_destroy_primary_surface_async(QXLWorker *qxl_worker, uint32_t surface_id)
+static void qxl_worker_destroy_primary_surface_async(QXLWorker *qxl_worker, uint32_t surface_id, uint64_t cookie)
 {
-    qxl_worker_destroy_primary_surface_helper(qxl_worker, surface_id, 1);
+    qxl_worker_destroy_primary_surface_helper(qxl_worker, surface_id, 1, cookie);
 }
 
 static void qxl_worker_create_primary_surface_helper(QXLWorker *qxl_worker, uint32_t surface_id,
-                                      QXLDevSurfaceCreate *surface, int async)
+                                      QXLDevSurfaceCreate *surface, int async, uint64_t cookie)
 {
     RedDispatcher *dispatcher = (RedDispatcher *)qxl_worker;
     RedWorkerMessage message;
@@ -356,6 +364,9 @@ static void qxl_worker_create_primary_surface_helper(QXLWorker *qxl_worker, uint
     dispatcher->primary_active = TRUE;
 
     write_message(dispatcher->channel, &message);
+    if (async) {
+        send_data(dispatcher->channel, &cookie, sizeof(cookie));
+    }
     send_data(dispatcher->channel, &surface_id, sizeof(uint32_t));
     send_data(dispatcher->channel, surface, sizeof(QXLDevSurfaceCreate));
     if (!async) {
@@ -369,13 +380,13 @@ static void qxl_worker_create_primary_surface_helper(QXLWorker *qxl_worker, uint
 static void qxl_worker_create_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id,
                                       QXLDevSurfaceCreate *surface)
 {
-    qxl_worker_create_primary_surface_helper(qxl_worker, surface_id, surface, 0);
+    qxl_worker_create_primary_surface_helper(qxl_worker, surface_id, surface, 0, 0);
 }
 
 static void qxl_worker_create_primary_surface_async(QXLWorker *qxl_worker, uint32_t surface_id,
-                                      QXLDevSurfaceCreate *surface)
+                                      QXLDevSurfaceCreate *surface, uint64_t cookie)
 {
-    qxl_worker_create_primary_surface_helper(qxl_worker, surface_id, surface, 1);
+    qxl_worker_create_primary_surface_helper(qxl_worker, surface_id, surface, 1, cookie);
 }
 
 static void qxl_worker_reset_image_cache(QXLWorker *qxl_worker)
@@ -399,7 +410,7 @@ static void qxl_worker_reset_cursor(QXLWorker *qxl_worker)
 }
 
 static void qxl_worker_destroy_surface_wait_helper(QXLWorker *qxl_worker, uint32_t surface_id,
-                                                   int async)
+                                                   int async, uint64_t cookie)
 {
     RedDispatcher *dispatcher = (RedDispatcher *)qxl_worker;
     RedWorkerMessage message;
@@ -411,6 +422,9 @@ static void qxl_worker_destroy_surface_wait_helper(QXLWorker *qxl_worker, uint32
     }
 
     write_message(dispatcher->channel, &message);
+    if (async) {
+        send_data(dispatcher->channel, &cookie, sizeof(cookie));
+    }
     send_data(dispatcher->channel, &surface_id, sizeof(uint32_t));
     if (async) {
         return;
@@ -421,12 +435,12 @@ static void qxl_worker_destroy_surface_wait_helper(QXLWorker *qxl_worker, uint32
 
 static void qxl_worker_destroy_surface_wait(QXLWorker *qxl_worker, uint32_t surface_id)
 {
-    qxl_worker_destroy_surface_wait_helper(qxl_worker, surface_id, 0);
+    qxl_worker_destroy_surface_wait_helper(qxl_worker, surface_id, 0, 0);
 }
 
-static void qxl_worker_destroy_surface_wait_async(QXLWorker *qxl_worker, uint32_t surface_id)
+static void qxl_worker_destroy_surface_wait_async(QXLWorker *qxl_worker, uint32_t surface_id, uint64_t cookie)
 {
-    qxl_worker_destroy_surface_wait_helper(qxl_worker, surface_id, 1);
+    qxl_worker_destroy_surface_wait_helper(qxl_worker, surface_id, 1, cookie);
 }
 
 static void qxl_worker_reset_memslots(QXLWorker *qxl_worker)
@@ -448,7 +462,7 @@ static void qxl_worker_wakeup(QXLWorker *qxl_worker)
     }
 }
 
-static void qxl_worker_oom_helper(QXLWorker *qxl_worker, int async)
+static void qxl_worker_oom_helper(QXLWorker *qxl_worker, int async, uint64_t cookie)
 {
     RedDispatcher *dispatcher = (RedDispatcher *)qxl_worker;
     RedWorkerMessage message;
@@ -461,25 +475,29 @@ static void qxl_worker_oom_helper(QXLWorker *qxl_worker, int async)
         }
         set_bit(RED_WORKER_PENDING_OOM, &dispatcher->pending);
         write_message(dispatcher->channel, &message);
+        if (async) {
+            send_data(dispatcher->channel, &cookie, sizeof(cookie));
+        }
     }
 }
 
 static void qxl_worker_oom(QXLWorker *qxl_worker)
 {
-    qxl_worker_oom_helper(qxl_worker, 0);
+    qxl_worker_oom_helper(qxl_worker, 0, 0);
 }
 
-static void qxl_worker_oom_async(QXLWorker *qxl_worker)
+static void qxl_worker_oom_async(QXLWorker *qxl_worker, uint64_t cookie)
 {
-    qxl_worker_oom_helper(qxl_worker, 1);
+    qxl_worker_oom_helper(qxl_worker, 1, cookie);
 }
 
-static void qxl_worker_flush_surfaces_async(QXLWorker *qxl_worker)
+static void qxl_worker_flush_surfaces_async(QXLWorker *qxl_worker, uint64_t cookie)
 {
     RedDispatcher *dispatcher = (RedDispatcher *)qxl_worker;
     RedWorkerMessage message = RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC;
 
     write_message(dispatcher->channel, &message);
+    send_data(dispatcher->channel, &cookie, sizeof(cookie));
 }
 
 static void qxl_worker_start(QXLWorker *qxl_worker)
diff --git a/server/red_worker.c b/server/red_worker.c
index 86a5065..e42bf38 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -9654,6 +9654,7 @@ static void handle_dev_input(EventListener *listener, uint32_t events)
     int ring_is_empty;
     int async = 0;
     int write_ready = 0;
+    uint64_t cookie;
 
     read_message(worker->channel, &message);
 
@@ -9669,6 +9670,7 @@ static void handle_dev_input(EventListener *listener, uint32_t events)
     case RED_WORKER_MESSAGE_OOM_ASYNC:
     case RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC:
         async = 1;
+        receive_data(worker->channel, &cookie, sizeof(cookie));
         break;
     case RED_WORKER_MESSAGE_UPDATE:
     case RED_WORKER_MESSAGE_ADD_MEMSLOT:
@@ -9888,7 +9890,7 @@ static void handle_dev_input(EventListener *listener, uint32_t events)
         red_error("message error");
     }
     if (async) {
-        worker->qxl->st->qif->async_complete(worker->qxl);
+        worker->qxl->st->qif->async_complete(worker->qxl, cookie);
     }
     if (write_ready) {
         message = RED_WORKER_MESSAGE_READY;
diff --git a/server/spice.h b/server/spice.h
index a715666..fec2476 100644
--- a/server/spice.h
+++ b/server/spice.h
@@ -125,16 +125,16 @@ struct QXLWorker {
     /* async versions of commands. when complete spice calls async_complete */
     void (*update_area_async)(QXLWorker *qxl_worker, uint32_t surface_id,
                        struct QXLRect *area, struct QXLRect *dirty_rects,
-                       uint32_t num_dirty_rects, uint32_t clear_dirty_region);
-    void (*add_memslot_async)(QXLWorker *worker, QXLDevMemSlot *slot);
-    void (*destroy_surfaces_async)(QXLWorker *worker);
-    void (*destroy_primary_surface_async)(QXLWorker *worker, uint32_t surface_id);
+                       uint32_t num_dirty_rects, uint32_t clear_dirty_region, uint64_t cookie);
+    void (*add_memslot_async)(QXLWorker *worker, QXLDevMemSlot *slot, uint64_t cookie);
+    void (*destroy_surfaces_async)(QXLWorker *worker, uint64_t cookie);
+    void (*destroy_primary_surface_async)(QXLWorker *worker, uint32_t surface_id, uint64_t cookie);
     void (*create_primary_surface_async)(QXLWorker *worker, uint32_t surface_id,
-                                   QXLDevSurfaceCreate *surface);
-    void (*destroy_surface_wait_async)(QXLWorker *worker, uint32_t surface_id);
-    void (*oom_async)(QXLWorker *worker);
+                                   QXLDevSurfaceCreate *surface, uint64_t cookie);
+    void (*destroy_surface_wait_async)(QXLWorker *worker, uint32_t surface_id, uint64_t cookie);
+    void (*oom_async)(QXLWorker *worker, uint64_t cookie);
     /* suspend support - stop+start+read_cmd_ring */
-    void (*flush_surfaces_async)(QXLWorker *worker);
+    void (*flush_surfaces_async)(QXLWorker *worker, uint64_t cookie);
 };
 
 typedef struct QXLDrawArea {
@@ -205,7 +205,7 @@ struct QXLInterface {
     int (*req_cursor_notification)(QXLInstance *qin);
     void (*notify_update)(QXLInstance *qin, uint32_t update_id);
     int (*flush_resources)(QXLInstance *qin);
-    void (*async_complete)(QXLInstance *qin);
+    void (*async_complete)(QXLInstance *qin, uint64_t cookie);
 };
 
 struct QXLInstance {
-- 
1.7.5.4



More information about the Spice-devel mailing list