[Spice-commits] 8 commits - server/cache-item.tmpl.c server/cursor-channel.c server/dcc.c server/dcc-encoders.c server/dcc-send.c server/display-channel.c server/red-channel.c server/red-channel.h server/red-worker.c server/red-worker.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Fri Feb 12 08:21:50 UTC 2016


 server/cache-item.tmpl.c |    2 +-
 server/cursor-channel.c  |    9 +--------
 server/dcc-encoders.c    |    3 +--
 server/dcc-send.c        |    3 +--
 server/dcc.c             |   36 +++++++++++++-----------------------
 server/display-channel.c |    8 +++-----
 server/red-channel.c     |    6 +++---
 server/red-channel.h     |    2 +-
 server/red-worker.c      |   46 ++++++++++++++++------------------------------
 server/red-worker.h      |    7 +++----
 10 files changed, 43 insertions(+), 79 deletions(-)

New commits:
commit efe5a0c501d157566522f87a394e29c5290e2185
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Feb 9 10:24:14 2016 +0000

    dcc: remove not necessary volatile specifications
    
    These automatic variable are used just inside the function.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/dcc.c b/server/dcc.c
index dd02d3e..bd25069 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -849,9 +849,9 @@ static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
     LzData *lz_data = &dcc->lz_data;
     JpegEncoderContext *jpeg = dcc->jpeg;
     LzContext *lz = dcc->lz;
-    volatile JpegEncoderImageType jpeg_in_type;
+    JpegEncoderImageType jpeg_in_type;
     int jpeg_size = 0;
-    volatile int has_alpha = FALSE;
+    int has_alpha = FALSE;
     int alpha_lz_size = 0;
     int comp_head_filled;
     int comp_head_left;
@@ -1017,7 +1017,7 @@ static int dcc_compress_image_quic(DisplayChannelClient *dcc, SpiceImage *dest,
 {
     QuicData *quic_data = &dcc->quic_data;
     QuicContext *quic = dcc->quic;
-    volatile QuicImageType type;
+    QuicImageType type;
     int size, stride;
     stat_start_time_t start_time;
     stat_start_time_init(&start_time, &DCC_TO_DC(dcc)->quic_stat);
commit fbdea0fa790ba3f836fe0c6d60441b716c7d0bd3
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Feb 8 19:57:58 2016 +0000

    CommonChannel: hold a reference to QXLInstance instead of RedWorker
    
    CommonChannel does not need to know about RedWorker.
    This reduce a bit dependencies between objects.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index bbaac34..197376a 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -489,7 +489,7 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd,
     spice_return_if_fail(cursor);
     spice_return_if_fail(cursor_cmd);
 
-    cursor_item = cursor_item_new(red_worker_get_qxl(cursor->common.worker),
+    cursor_item = cursor_item_new(cursor->common.qxl,
                                   cursor_cmd, group_id);
 
     switch (cursor_cmd->type) {
diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index 0923c9c..c810b8e 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -456,7 +456,6 @@ void dcc_free_glz_drawable_instance(DisplayChannelClient *dcc,
                                     GlzDrawableInstanceItem *instance)
 {
     DisplayChannel *display_channel = DCC_TO_DC(dcc);
-    RedWorker *worker = display_channel->common.worker;
     RedGlzDrawable *glz_drawable;
 
     spice_assert(instance);
@@ -484,7 +483,7 @@ void dcc_free_glz_drawable_instance(DisplayChannelClient *dcc,
         if (drawable) {
             ring_remove(&glz_drawable->drawable_link);
         }
-        red_drawable_unref(worker, glz_drawable->red_drawable,
+        red_drawable_unref(display_channel, glz_drawable->red_drawable,
                            glz_drawable->group_id);
         display_channel->glz_drawable_count--;
         if (ring_item_is_linked(&glz_drawable->link)) {
diff --git a/server/dcc-send.c b/server/dcc-send.c
index 3af5760..ab07634 100644
--- a/server/dcc-send.c
+++ b/server/dcc-send.c
@@ -2305,8 +2305,7 @@ static void marshall_gl_scanout(RedChannelClient *rcc,
 {
     DisplayChannelClient *dcc = RCC_TO_DCC(rcc);
     DisplayChannel *display_channel = DCC_TO_DC(dcc);
-    RedWorker *worker = display_channel->common.worker;
-    QXLInstance* qxl = red_worker_get_qxl(worker);
+    QXLInstance* qxl = display_channel->common.qxl;
     SpiceMsgDisplayGlScanoutUnix *so = &qxl->st->scanout;
 
     pthread_mutex_lock(&qxl->st->scanout_mutex);
diff --git a/server/dcc.c b/server/dcc.c
index d28c4ee..dd02d3e 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -445,7 +445,7 @@ void dcc_start(DisplayChannelClient *dcc)
 {
     DisplayChannel *display = DCC_TO_DC(dcc);
     RedChannelClient *rcc = RED_CHANNEL_CLIENT(dcc);
-    QXLInstance *qxl = red_worker_get_qxl(COMMON_CHANNEL(display)->worker);
+    QXLInstance *qxl = display->common.qxl;
 
     red_channel_client_push_set_ack(RED_CHANNEL_CLIENT(dcc));
 
diff --git a/server/display-channel.c b/server/display-channel.c
index 78c984f..28304b3 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -241,8 +241,7 @@ static void stop_streams(DisplayChannel *display)
 void display_channel_surface_unref(DisplayChannel *display, uint32_t surface_id)
 {
     RedSurface *surface = &display->surfaces[surface_id];
-    RedWorker *worker = COMMON_CHANNEL(display)->worker;
-    QXLInstance *qxl = red_worker_get_qxl(worker);
+    QXLInstance *qxl = display->common.qxl;
     DisplayChannelClient *dcc;
     RingItem *link, *next;
 
@@ -1445,7 +1444,7 @@ void display_channel_drawable_unref(DisplayChannel *display, Drawable *drawable)
         ring_remove(item);
     }
     if (drawable->red_drawable) {
-        red_drawable_unref(COMMON_CHANNEL(display)->worker, drawable->red_drawable, drawable->group_id);
+        red_drawable_unref(display, drawable->red_drawable, drawable->group_id);
     }
     drawable_free(display, drawable);
     display->drawable_count--;
@@ -2155,8 +2154,7 @@ void display_channel_gl_scanout(DisplayChannel *display)
 
 static void set_gl_draw_async_count(DisplayChannel *display, int num)
 {
-    RedWorker *worker = COMMON_CHANNEL(display)->worker;
-    QXLInstance *qxl = red_worker_get_qxl(worker);
+    QXLInstance *qxl = display->common.qxl;
 
     display->gl_draw_async_count = num;
 
diff --git a/server/red-worker.c b/server/red-worker.c
index f6223ef..ff68499 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -129,7 +129,7 @@ static void common_release_recv_buf(RedChannelClient *rcc, uint16_t type, uint32
     }
 }
 
-void red_drawable_unref(RedWorker *worker, RedDrawable *red_drawable,
+void red_drawable_unref(DisplayChannel *display, RedDrawable *red_drawable,
                         uint32_t group_id)
 {
     QXLReleaseInfoExt release_info_ext;
@@ -137,10 +137,10 @@ void red_drawable_unref(RedWorker *worker, RedDrawable *red_drawable,
     if (--red_drawable->refs) {
         return;
     }
-    worker->display_channel->red_drawable_count--;
+    display->red_drawable_count--;
     release_info_ext.group_id = group_id;
     release_info_ext.info = red_drawable->release_info;
-    worker->qxl->st->qif->release_resource(worker->qxl, release_info_ext);
+    display->common.qxl->st->qif->release_resource(display->common.qxl, release_info_ext);
     red_put_drawable(red_drawable);
     free(red_drawable);
 }
@@ -243,7 +243,7 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
                                              worker->process_display_generation);
             }
             // release the red_drawable
-            red_drawable_unref(worker, red_drawable, ext_cmd.group_id);
+            red_drawable_unref(worker->display_channel, red_drawable, ext_cmd.group_id);
             break;
         }
         case QXL_CMD_UPDATE: {
@@ -469,7 +469,7 @@ CommonChannelClient *common_channel_new_client(CommonChannel *common,
         return NULL;
     }
     CommonChannelClient *common_cc = (CommonChannelClient*)rcc;
-    common_cc->id = common->worker->qxl->id;
+    common_cc->id = common->qxl->id;
     common->during_target_migrate = mig_target;
 
     // TODO: move wide/narrow ack setting to red_channel.
@@ -510,7 +510,7 @@ CommonChannel *red_worker_new_channel(RedWorker *worker, int size,
     red_channel_set_stat_node(channel, stat_add_node(worker->stat, name, TRUE));
 
     common = (CommonChannel *)channel;
-    common->worker = worker;
+    common->qxl = worker->qxl;
     return common;
 }
 
diff --git a/server/red-worker.h b/server/red-worker.h
index 005c15f..1285942 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -38,7 +38,7 @@ typedef struct CommonChannelClient {
 typedef struct CommonChannel {
     RedChannel base; // Must be the first thing
 
-    struct RedWorker *worker;
+    QXLInstance *qxl;
     uint8_t recv_buf[CHANNEL_RECEIVE_BUF_SIZE];
     uint32_t id_alloc; // bitfield. TODO - use this instead of shift scheme.
     int during_target_migrate; /* TRUE when the client that is associated with the channel
@@ -97,7 +97,8 @@ QXLInstance* red_worker_get_qxl(RedWorker *worker);
 RedChannel* red_worker_get_cursor_channel(RedWorker *worker);
 RedChannel* red_worker_get_display_channel(RedWorker *worker);
 
-void red_drawable_unref(RedWorker *worker, RedDrawable *red_drawable,
+struct DisplayChannel;
+void red_drawable_unref(struct DisplayChannel *display, RedDrawable *red_drawable,
                         uint32_t group_id);
 
 CommonChannel *red_worker_new_channel(RedWorker *worker, int size,
commit 79e50495fe53a34cdbf2e524da2dcac4e11ee811
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Feb 8 19:43:42 2016 +0000

    ccc: remove unused field
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/red-worker.c b/server/red-worker.c
index 12ce463..f6223ef 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -469,7 +469,6 @@ CommonChannelClient *common_channel_new_client(CommonChannel *common,
         return NULL;
     }
     CommonChannelClient *common_cc = (CommonChannelClient*)rcc;
-    common_cc->worker = common->worker;
     common_cc->id = common->worker->qxl->id;
     common->during_target_migrate = mig_target;
 
diff --git a/server/red-worker.h b/server/red-worker.h
index f14a553..005c15f 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -28,7 +28,6 @@ typedef struct CommonChannelClient {
     RedChannelClient base;
 
     uint32_t id;
-    RedWorker *worker;
     int is_low_bandwidth;
 } CommonChannelClient;
 
commit 1df95105813cde54585afa9cc983f8cf189d93b1
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Feb 8 19:42:10 2016 +0000

    worker: remove unused red_worker_get_memslot function
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/red-worker.c b/server/red-worker.c
index ea6bcf5..12ce463 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -99,13 +99,6 @@ QXLInstance* red_worker_get_qxl(RedWorker *worker)
     return worker->qxl;
 }
 
-RedMemSlotInfo* red_worker_get_memslot(RedWorker *worker)
-{
-    spice_return_val_if_fail(worker != NULL, NULL);
-
-    return &worker->mem_slots;
-}
-
 static int display_is_connected(RedWorker *worker)
 {
     return (worker->display_channel && red_channel_is_connected(
diff --git a/server/red-worker.h b/server/red-worker.h
index 91533e1..f14a553 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -97,7 +97,6 @@ bool       red_worker_run(RedWorker *worker);
 QXLInstance* red_worker_get_qxl(RedWorker *worker);
 RedChannel* red_worker_get_cursor_channel(RedWorker *worker);
 RedChannel* red_worker_get_display_channel(RedWorker *worker);
-RedMemSlotInfo* red_worker_get_memslot(RedWorker *worker);
 
 void red_drawable_unref(RedWorker *worker, RedDrawable *red_drawable,
                         uint32_t group_id);
commit 721528fe3788b6ec6b503514aa4f6d37bc363a61
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Feb 8 05:33:02 2016 +0000

    remove unused structure definition
    
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 4c15582..bbaac34 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -45,13 +45,6 @@ typedef struct CursorItem {
 
 G_STATIC_ASSERT(sizeof(CursorItem) <= QXL_CURSUR_DEVICE_DATA_SIZE);
 
-typedef struct LocalCursor {
-    CursorItem base;
-    SpicePoint16 position;
-    uint32_t data_size;
-    SpiceCursor red_cursor;
-} LocalCursor;
-
 typedef struct CursorPipeItem {
     PipeItem base;
     CursorItem *cursor_item;
commit d56745df191e2013f00c50e9cbbb9f686c2adf9c
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Feb 8 05:11:27 2016 +0000

    dcc: remove group_id from compression functions
    
    The parameter was not used.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/dcc.c b/server/dcc.c
index 4d02d1c..d28c4ee 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -782,7 +782,7 @@ glz:
 
 static int dcc_compress_image_lz(DisplayChannelClient *dcc,
                                  SpiceImage *dest, SpiceBitmap *src,
-                                 compress_send_data_t* o_comp_data, uint32_t group_id)
+                                 compress_send_data_t* o_comp_data)
 {
     LzData *lz_data = &dcc->lz_data;
     LzContext *lz = dcc->lz;
@@ -843,8 +843,7 @@ static int dcc_compress_image_lz(DisplayChannelClient *dcc,
 }
 
 static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
-                                   SpiceBitmap *src, compress_send_data_t* o_comp_data,
-                                   uint32_t group_id)
+                                   SpiceBitmap *src, compress_send_data_t* o_comp_data)
 {
     JpegData *jpeg_data = &dcc->jpeg_data;
     LzData *lz_data = &dcc->lz_data;
@@ -968,8 +967,7 @@ static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
 
 #ifdef USE_LZ4
 static int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest,
-                                  SpiceBitmap *src, compress_send_data_t* o_comp_data,
-                                  uint32_t group_id)
+                                  SpiceBitmap *src, compress_send_data_t* o_comp_data)
 {
     Lz4Data *lz4_data = &dcc->lz4_data;
     Lz4EncoderContext *lz4 = dcc->lz4;
@@ -1015,8 +1013,7 @@ static int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest,
 #endif
 
 static int dcc_compress_image_quic(DisplayChannelClient *dcc, SpiceImage *dest,
-                                   SpiceBitmap *src, compress_send_data_t* o_comp_data,
-                                   uint32_t group_id)
+                                   SpiceBitmap *src, compress_send_data_t* o_comp_data)
 {
     QuicData *quic_data = &dcc->quic_data;
     QuicContext *quic = dcc->quic;
@@ -1094,7 +1091,6 @@ int dcc_compress_image(DisplayChannelClient *dcc,
     DisplayChannel *display_channel = DCC_TO_DC(dcc);
     SpiceImageCompression image_compression = dcc->image_compression;
     int quic_compress = FALSE;
-    uint32_t group_id;
 
     if ((image_compression == SPICE_IMAGE_COMPRESSION_OFF) ||
         ((src->y * src->stride) < MIN_SIZE_TO_COMPRESS)) { // TODO: change the size cond
@@ -1139,12 +1135,6 @@ int dcc_compress_image(DisplayChannelClient *dcc,
         }
     }
 
-    if (drawable != NULL) {
-        group_id = drawable->group_id;
-    } else {
-        group_id = red_worker_get_memslot(display_channel->common.worker)->internal_groupslot_id;
-    }
-
     if (quic_compress) {
 #ifdef COMPRESS_DEBUG
         spice_info("QUIC compress");
@@ -1155,10 +1145,10 @@ int dcc_compress_image(DisplayChannelClient *dcc,
             (image_compression == SPICE_IMAGE_COMPRESSION_AUTO_GLZ))) {
             // if we use lz for alpha, the stride can't be extra
             if (src->format != SPICE_BITMAP_FMT_RGBA || !bitmap_has_extra_stride(src)) {
-                return dcc_compress_image_jpeg(dcc, dest, src, o_comp_data, group_id);
+                return dcc_compress_image_jpeg(dcc, dest, src, o_comp_data);
             }
         }
-        return dcc_compress_image_quic(dcc, dest, src, o_comp_data, group_id);
+        return dcc_compress_image_quic(dcc, dest, src, o_comp_data);
     } else {
         int glz;
         int ret;
@@ -1194,10 +1184,10 @@ int dcc_compress_image(DisplayChannelClient *dcc,
                 bitmap_fmt_is_rgb(src->format) &&
                 red_channel_client_test_remote_cap(&dcc->common.base,
                         SPICE_DISPLAY_CAP_LZ4_COMPRESSION)) {
-                ret = dcc_compress_image_lz4(dcc, dest, src, o_comp_data, group_id);
+                ret = dcc_compress_image_lz4(dcc, dest, src, o_comp_data);
             } else
 #endif
-                ret = dcc_compress_image_lz(dcc, dest, src, o_comp_data, group_id);
+                ret = dcc_compress_image_lz(dcc, dest, src, o_comp_data);
 #ifdef COMPRESS_DEBUG
             spice_info("LZ LOCAL compress");
 #endif
commit 448700bfb44d4afadaa0d0546e098b2a7ab86d08
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed Feb 3 16:56:09 2016 +0000

    channel: rename misleading functions
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/cache-item.tmpl.c b/server/cache-item.tmpl.c
index 09add79..efc26c3 100644
--- a/server/cache-item.tmpl.c
+++ b/server/cache-item.tmpl.c
@@ -83,7 +83,7 @@ static void FUNC_NAME(remove)(CHANNELCLIENT *channel_client, CacheItem *item)
     channel_client->VAR_NAME(available) += item->size;
 
     red_channel_pipe_item_init(&channel->common.base, &item->u.pipe_data, PIPE_ITEM_TYPE_INVAL_ONE);
-    red_channel_client_pipe_add_tail(&channel_client->common.base, &item->u.pipe_data); // for now
+    red_channel_client_pipe_add_tail_and_push(&channel_client->common.base, &item->u.pipe_data); // for now
 }
 
 static int FUNC_NAME(add)(CHANNELCLIENT *channel_client, uint64_t id, size_t size)
diff --git a/server/dcc.c b/server/dcc.c
index 5ccbda1..4d02d1c 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -325,7 +325,7 @@ void dcc_append_drawable(DisplayChannelClient *dcc, Drawable *drawable)
     DrawablePipeItem *dpi = drawable_pipe_item_new(dcc, drawable);
 
     add_drawable_surface_images(dcc, drawable);
-    red_channel_client_pipe_add_tail(RED_CHANNEL_CLIENT(dcc), &dpi->dpi_pipe_item);
+    red_channel_client_pipe_add_tail_and_push(RED_CHANNEL_CLIENT(dcc), &dpi->dpi_pipe_item);
 }
 
 void dcc_add_drawable_after(DisplayChannelClient *dcc, Drawable *drawable, PipeItem *pos)
diff --git a/server/red-channel.c b/server/red-channel.c
index 190779a..3cc12f3 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -1707,13 +1707,13 @@ int red_channel_client_pipe_item_is_linked(RedChannelClient *rcc,
     return ring_item_is_linked(&item->link);
 }
 
-void red_channel_client_pipe_add_tail_no_push(RedChannelClient *rcc,
+void red_channel_client_pipe_add_tail(RedChannelClient *rcc,
                                               PipeItem *item)
 {
     client_pipe_add(rcc, item, rcc->pipe.prev);
 }
 
-void red_channel_client_pipe_add_tail(RedChannelClient *rcc, PipeItem *item)
+void red_channel_client_pipe_add_tail_and_push(RedChannelClient *rcc, PipeItem *item)
 {
     if (client_pipe_add(rcc, item, rcc->pipe.prev)) {
         red_channel_client_push(rcc);
@@ -2292,7 +2292,7 @@ void red_channel_pipes_new_add(RedChannel *channel, new_pipe_item_t creator, voi
 void red_channel_pipes_new_add_tail(RedChannel *channel, new_pipe_item_t creator, void *data)
 {
     red_channel_pipes_create_batch(channel, creator, data,
-                                     red_channel_client_pipe_add_tail_no_push);
+                                     red_channel_client_pipe_add_tail);
 }
 
 uint32_t red_channel_max_pipe_size(RedChannel *channel)
diff --git a/server/red-channel.h b/server/red-channel.h
index b5ab7ac..c49c506 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -487,7 +487,7 @@ void red_channel_client_pipe_add(RedChannelClient *rcc, PipeItem *item);
 void red_channel_client_pipe_add_after(RedChannelClient *rcc, PipeItem *item, PipeItem *pos);
 int red_channel_client_pipe_item_is_linked(RedChannelClient *rcc, PipeItem *item);
 void red_channel_client_pipe_remove_and_release(RedChannelClient *rcc, PipeItem *item);
-void red_channel_client_pipe_add_tail(RedChannelClient *rcc, PipeItem *item);
+void red_channel_client_pipe_add_tail_and_push(RedChannelClient *rcc, PipeItem *item);
 /* for types that use this routine -> the pipe item should be freed */
 void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type);
 void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type);
commit b98aa6860da4395b98e7f5a0fb6fdd31f82069d9
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed Jan 27 12:05:11 2016 +0000

    worker: simplify process loops
    
    It was not clear when req_cmd_notification was called.
    This code reproduce just the old behavior but is easier to read.
    
    Steps are:
    
    // original
    
    if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
        worker->display_poll_tries++;
        worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
        return n;
    }
    if (worker->display_poll_tries > CMD_RING_POLL_RETRIES ||
                 worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
        worker->display_poll_tries++;
        return n;
    }
    continue;
    
    // split if
    
    if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
        worker->display_poll_tries++;
        worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
        return n;
    }
    if (worker->display_poll_tries > CMD_RING_POLL_RETRIES) {
        worker->display_poll_tries++;
        return n;
    }
    if (worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
        worker->display_poll_tries++;
        return n;
    }
    continue;
    
    // order inside if
    
    if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
        worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
        worker->display_poll_tries++;
        return n;
    }
    if (worker->display_poll_tries > CMD_RING_POLL_RETRIES) {
        worker->display_poll_tries++;
        return n;
    }
    if (worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
        worker->display_poll_tries++;
        return n;
    }
    continue;
    
    // consider cases
    
    if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
        worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
        worker->display_poll_tries++;
        return n;
    }
    if (worker->display_poll_tries > CMD_RING_POLL_RETRIES) {
        worker->display_poll_tries++;
        return n;
    }
    if (worker->display_poll_tries == CMD_RING_POLL_RETRIES) {
        if (worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
            worker->display_poll_tries++;
            return n;
        }
        continue;
    }
    // unreachable
    
    // invert if
    
    if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
        worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
        worker->display_poll_tries++;
        return n;
    }
    if (worker->display_poll_tries > CMD_RING_POLL_RETRIES) {
        worker->display_poll_tries++;
        return n;
    }
    if (worker->display_poll_tries == CMD_RING_POLL_RETRIES) {
        if (!worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
            continue;
        }
        worker->display_poll_tries++;
        return n;
    }
    // unreachable
    
    // reuse code
    
    if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
        worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
    } else if (worker->display_poll_tries > CMD_RING_POLL_RETRIES) {
    } else if (worker->display_poll_tries == CMD_RING_POLL_RETRIES) {
        if (!worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
            continue;
        }
    }
    worker->display_poll_tries++;
    return n;
    
    // remove empty if
    
    if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
        worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
    } else if (worker->display_poll_tries == CMD_RING_POLL_RETRIES) {
        if (!worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
            continue;
        }
    }
    worker->display_poll_tries++;
    return n;
    
    // collapse two conditions
    
    if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
        worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
    } else if (worker->display_poll_tries == CMD_RING_POLL_RETRIES &&
               !worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
        continue;
    }
    worker->display_poll_tries++;
    return n;
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/red-worker.c b/server/red-worker.c
index e7d0671..ea6bcf5 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -167,16 +167,13 @@ static int red_process_cursor(RedWorker *worker, int *ring_is_empty)
         if (!worker->qxl->st->qif->get_cursor_command(worker->qxl, &ext_cmd)) {
             *ring_is_empty = TRUE;
             if (worker->cursor_poll_tries < CMD_RING_POLL_RETRIES) {
-                worker->cursor_poll_tries++;
                 worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
-                return n;
+            } else if (worker->cursor_poll_tries == CMD_RING_POLL_RETRIES &&
+                       !worker->qxl->st->qif->req_cursor_notification(worker->qxl)) {
+                continue;
             }
-            if (worker->cursor_poll_tries > CMD_RING_POLL_RETRIES ||
-                worker->qxl->st->qif->req_cursor_notification(worker->qxl)) {
-                worker->cursor_poll_tries++;
-                return n;
-            }
-            continue;
+            worker->cursor_poll_tries++;
+            return n;
         }
         worker->cursor_poll_tries = 0;
         switch (ext_cmd.cmd.type) {
@@ -228,16 +225,13 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
         if (!worker->qxl->st->qif->get_command(worker->qxl, &ext_cmd)) {
             *ring_is_empty = TRUE;
             if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
-                worker->display_poll_tries++;
                 worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
-                return n;
+            } else if (worker->display_poll_tries == CMD_RING_POLL_RETRIES &&
+                       !worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
+                continue;
             }
-            if (worker->display_poll_tries > CMD_RING_POLL_RETRIES ||
-                         worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
-                worker->display_poll_tries++;
-                return n;
-            }
-            continue;
+            worker->display_poll_tries++;
+            return n;
         }
 
         if (worker->record_fd)


More information about the Spice-commits mailing list