[Spice-devel] [PATCH v2 04/40] server/red_worker: add red_channel_push

Alon Levy alevy at redhat.com
Wed Mar 2 00:31:27 PST 2011


---
 server/red_worker.c |   54 ++++++++++++++++++++++++++++----------------------
 1 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/server/red_worker.c b/server/red_worker.c
index 3af5924..d70447b 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -969,7 +969,7 @@ typedef struct BitmapData {
 
 static void red_draw_qxl_drawable(RedWorker *worker, Drawable *drawable);
 static void red_current_flush(RedWorker *worker, int surface_id);
-static void display_channel_push(RedWorker *worker);
+static void red_channel_push(RedChannel *channel);
 #ifdef DRAW_ALL
 #define red_update_area(worker, rect, surface_id)
 #define red_draw_drawable(worker, item)
@@ -4560,7 +4560,7 @@ static void red_add_surface_image(RedWorker *worker, int surface_id)
     /* not allowing lossy compression because probably, especially if it is a primary surface,
        it combines both "picture-like" areas with areas that are more "artificial"*/
     red_add_surface_area_image(worker, surface_id, &area, NULL, FALSE);
-    display_channel_push(worker);
+    red_channel_push(&worker->display_channel->common.base);
 }
 
 typedef struct {
@@ -8260,7 +8260,7 @@ static void red_send_cursor(CursorChannel *cursor_channel, CursorItem *cursor)
 
     red_channel_begin_send_message(channel);
 
-    red_release_cursor(cursor_channel->common.worker, cursor);
+    red_release_cursor(worker, cursor);
 }
 
 static void red_send_surface_create(DisplayChannel *display, SpiceMsgSurfaceCreate *surface_create)
@@ -8407,13 +8407,24 @@ static void display_channel_send_item(RedChannel *base, PipeItem *pipe_item)
     red_unref_channel((RedChannel *)display_channel);
 }
 
-static void display_channel_push(RedWorker *worker)
+void red_channel_push(RedChannel *channel)
 {
     PipeItem *pipe_item;
 
-    while ((pipe_item = red_channel_pipe_get((RedChannel *)worker->display_channel))) {
-        display_channel_send_item((RedChannel *)worker->display_channel, pipe_item);
+    if (!channel->during_send) {
+        channel->during_send = TRUE;
+    } else {
+        return;
     }
+
+    if (channel->send_data.blocked) {
+        red_channel_send(channel);
+    }
+
+    while ((pipe_item = red_channel_pipe_get(channel))) {
+        channel->send_item(channel, pipe_item);
+    }
+    channel->during_send = FALSE;
 }
 
 static void cursor_channel_send_item(RedChannel *channel, PipeItem *pipe_item)
@@ -8462,19 +8473,14 @@ static void cursor_channel_send_item(RedChannel *channel, PipeItem *pipe_item)
     red_unref_channel(channel);
 }
 
-static void cursor_channel_push(RedWorker *worker)
-{
-    PipeItem *pipe_item;
-
-    while ((pipe_item = red_channel_pipe_get((RedChannel *)worker->cursor_channel))) {
-        cursor_channel_send_item(&worker->cursor_channel->common.base, pipe_item);
-    }
-}
-
 static inline void red_push(RedWorker *worker)
 {
-    cursor_channel_push(worker);
-    display_channel_push(worker);
+    if (worker->cursor_channel) {
+        red_channel_push(&worker->cursor_channel->common.base);
+    }
+    if (worker->display_channel) {
+        red_channel_push(&worker->display_channel->common.base);
+    }
 }
 
 typedef struct ShowTreeData {
@@ -8802,7 +8808,7 @@ static inline void flush_display_commands(RedWorker *worker)
         }
 
         while (red_process_commands(worker, MAX_PIPE_SIZE, &ring_is_empty)) {
-            display_channel_push(worker);
+            red_channel_push(&worker->display_channel->common.base);
         }
 
         if (ring_is_empty) {
@@ -8811,7 +8817,7 @@ static inline void flush_display_commands(RedWorker *worker)
         end_time = red_now() + DISPLAY_CLIENT_TIMEOUT * 10;
         int sleep_count = 0;
         for (;;) {
-            display_channel_push(worker);
+            red_channel_push(&worker->display_channel->common.base);
             if (!worker->display_channel ||
                                          worker->display_channel->common.base.pipe_size <= MAX_PIPE_SIZE) {
                 break;
@@ -8844,7 +8850,7 @@ static inline void flush_cursor_commands(RedWorker *worker)
         }
 
         while (red_process_cursor(worker, MAX_PIPE_SIZE, &ring_is_empty)) {
-            cursor_channel_push(worker);
+            red_channel_push(&worker->cursor_channel->common.base);
         }
 
         if (ring_is_empty) {
@@ -8853,7 +8859,7 @@ static inline void flush_cursor_commands(RedWorker *worker)
         end_time = red_now() + DISPLAY_CLIENT_TIMEOUT * 10;
         int sleep_count = 0;
         for (;;) {
-            cursor_channel_push(worker);
+            red_channel_push(&worker->cursor_channel->common.base);
             if (!worker->cursor_channel ||
                                         worker->cursor_channel->common.base.pipe_size <= MAX_PIPE_SIZE) {
                 break;
@@ -8889,7 +8895,7 @@ static void push_new_primary_surface(RedWorker *worker)
         if (!display_channel->common.base.migrate) {
             red_create_surface_item(worker, 0);
         }
-        display_channel_push(worker);
+        red_channel_push(&worker->display_channel->common.base);
     }
 }
 
@@ -9939,7 +9945,7 @@ static inline void handle_dev_create_primary_surface(RedWorker *worker)
 
     if (worker->display_channel) {
         red_pipe_add_verb(&worker->display_channel->common.base, SPICE_MSG_DISPLAY_MARK);
-        display_channel_push(worker);
+        red_channel_push(&worker->display_channel->common.base);
     }
 
     if (worker->cursor_channel) {
@@ -10010,7 +10016,7 @@ static void handle_dev_input(EventListener *listener, uint32_t events)
     case RED_WORKER_MESSAGE_OOM:
         ASSERT(worker->running);
         while (red_process_commands(worker, MAX_PIPE_SIZE, &ring_is_empty)) {
-            display_channel_push(worker);
+            red_channel_push(&worker->display_channel->common.base);
         }
         if (worker->qxl->st->qif->flush_resources(worker->qxl) == 0) {
             red_printf("oom current %u pipe %u", worker->current_size,
-- 
1.7.4.1



More information about the Spice-devel mailing list