[Spice-commits] 6 commits - server/display-channel.c server/display-channel.h server/main-channel.c server/red-channel.c server/red-channel.h server/red-common.h server/red-worker.c server/reds-private.h server/reds.c server/stream.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Wed Sep 21 15:44:07 UTC 2016


 server/display-channel.c |   42 ++++++++++++------------
 server/display-channel.h |   11 +-----
 server/main-channel.c    |   20 +++++------
 server/red-channel.c     |   80 +++++++++++++++++++++--------------------------
 server/red-channel.h     |   12 +------
 server/red-common.h      |   18 ++++++++++
 server/red-worker.c      |    8 ++--
 server/reds-private.h    |    3 +
 server/reds.c            |   66 ++++++++++++++++++--------------------
 server/stream.c          |   24 +++++++-------
 10 files changed, 142 insertions(+), 142 deletions(-)

New commits:
commit 6d4db4f0bfdb3817afbe2a78dc03e0adfc8cee65
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Sep 20 08:49:42 2016 +0100

    Base FOREACH_DCC on GLIST_FOREACH
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/display-channel.c b/server/display-channel.c
index 88a9ba3..8b949a2 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -174,7 +174,7 @@ void display_channel_surface_unref(DisplayChannel *display, uint32_t surface_id)
     RedSurface *surface = &display->priv->surfaces[surface_id];
     QXLInstance *qxl = display->common.qxl;
     DisplayChannelClient *dcc;
-    GList *link, *next;
+    GListIter iter;
 
     if (--surface->refs != 0) {
         return;
@@ -196,7 +196,7 @@ void display_channel_surface_unref(DisplayChannel *display, uint32_t surface_id)
 
     region_destroy(&surface->draw_dirty_region);
     surface->context.canvas = NULL;
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         dcc_destroy_surface(dcc, surface_id);
     }
 
@@ -214,7 +214,7 @@ static void streams_update_visible_region(DisplayChannel *display, Drawable *dra
 {
     Ring *ring;
     RingItem *item;
-    GList *link, *next;
+    GListIter iter;
     DisplayChannelClient *dcc;
 
     if (!red_channel_is_connected(RED_CHANNEL(display))) {
@@ -238,7 +238,7 @@ static void streams_update_visible_region(DisplayChannel *display, Drawable *dra
             continue;
         }
 
-        FOREACH_DCC(display, link, next, dcc) {
+        FOREACH_DCC(display, iter, dcc) {
             agent = dcc_get_stream_agent(dcc, display_channel_get_stream_id(display, stream));
 
             if (region_intersects(&agent->vis_region, &drawable->tree_item.base.rgn)) {
@@ -253,10 +253,10 @@ static void streams_update_visible_region(DisplayChannel *display, Drawable *dra
 static void pipes_add_drawable(DisplayChannel *display, Drawable *drawable)
 {
     DisplayChannelClient *dcc;
-    GList *link, *next;
+    GListIter iter;
 
     spice_warn_if_fail(drawable->pipes == NULL);
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         dcc_prepend_drawable(dcc, drawable);
     }
 }
@@ -281,9 +281,9 @@ static void pipes_add_drawable_after(DisplayChannel *display,
         return;
     }
     if (num_other_linked != g_list_length(display->common.base.clients)) {
-        GList *link, *next;
+        GListIter iter;
         spice_debug("TODO: not O(n^2)");
-        FOREACH_DCC(display, link, next, dcc) {
+        FOREACH_DCC(display, iter, dcc) {
             int sent = 0;
             GList *l;
             for (l = pos_after->pipes; l != NULL; l = l->next) {
@@ -434,7 +434,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem *
 
             DisplayChannelClient *dcc;
             GList *dpi_item;
-            GList *link, *next;
+            GListIter iter;
 
             other_drawable->refs++;
             current_remove_drawable(display, other_drawable);
@@ -443,7 +443,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem *
              * (or will receive) other_drawable */
             dpi_item = g_list_first(other_drawable->pipes);
             /* dpi contains a sublist of dcc's, ordered the same */
-            FOREACH_DCC(display, link, next, dcc) {
+            FOREACH_DCC(display, iter, dcc) {
                 if (dpi_item && dcc == ((RedDrawablePipeItem *) dpi_item->data)->dcc) {
                     dpi_item = dpi_item->next;
                 } else {
@@ -1163,24 +1163,24 @@ void display_channel_flush_all_surfaces(DisplayChannel *display)
 
 void display_channel_free_glz_drawables_to_free(DisplayChannel *display)
 {
-    GList *link, *next;
+    GListIter iter;
     DisplayChannelClient *dcc;
 
     spice_return_if_fail(display);
 
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         image_encoders_free_glz_drawables_to_free(dcc_get_encoders(dcc));
     }
 }
 
 void display_channel_free_glz_drawables(DisplayChannel *display)
 {
-    GList *link, *next;
+    GListIter iter;
     DisplayChannelClient *dcc;
 
     spice_return_if_fail(display);
 
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         image_encoders_free_glz_drawables(dcc_get_encoders(dcc));
     }
 }
@@ -1219,11 +1219,11 @@ void display_channel_free_some(DisplayChannel *display)
 {
     int n = 0;
     DisplayChannelClient *dcc;
-    GList *link, *next;
+    GListIter iter;
 
     spice_debug("#draw=%d, #glz_draw=%d", display->priv->drawable_count,
                 display->priv->encoder_shared_data.glz_drawable_count);
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         ImageEncoders *encoders = dcc_get_encoders(dcc);
 
         // encoding using the dictionary is prevented since the following operations might
@@ -1237,7 +1237,7 @@ void display_channel_free_some(DisplayChannel *display)
         free_one_drawable(display, TRUE);
     }
 
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         ImageEncoders *encoders = dcc_get_encoders(dcc);
 
         image_encoders_glz_encode_unlock(encoders);
@@ -1703,10 +1703,10 @@ void display_channel_update(DisplayChannel *display,
 static void clear_surface_drawables_from_pipes(DisplayChannel *display, int surface_id,
                                                int wait_if_used)
 {
-    GList *link, *next;
+    GListIter iter;
     DisplayChannelClient *dcc;
 
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         if (!dcc_clear_surface_drawables_from_pipe(dcc, surface_id, wait_if_used)) {
             red_channel_client_disconnect(RED_CHANNEL_CLIENT(dcc));
         }
@@ -1770,9 +1770,9 @@ void display_channel_destroy_surfaces(DisplayChannel *display)
 static void send_create_surface(DisplayChannel *display, int surface_id, int image_ready)
 {
     DisplayChannelClient *dcc;
-    GList *link, *next;
+    GListIter iter;
 
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         dcc_create_surface(dcc, surface_id);
         if (image_ready)
             dcc_push_surface_image(dcc, surface_id);
diff --git a/server/display-channel.h b/server/display-channel.h
index 20f299d..3da2b5f 100644
--- a/server/display-channel.h
+++ b/server/display-channel.h
@@ -214,14 +214,9 @@ struct DisplayChannel {
     DisplayChannelPrivate priv[1];
 };
 
-#define FOREACH_DCC(channel, _link, _next, _data)                   \
-    for (_link = (channel ? RED_CHANNEL(channel)->clients : NULL), \
-         _next = (_link ? _link->next : NULL), \
-         _data = (_link ? _link->data : NULL); \
-         _link; \
-         _link = _next, \
-         _next = (_link ? _link->next : NULL), \
-         _data = (_link ? _link->data : NULL))
+#define FOREACH_DCC(_channel, _iter, _data) \
+    GLIST_FOREACH((_channel ? RED_CHANNEL(_channel)->clients : NULL), \
+                  _iter, DisplayChannelClient, _data)
 
 int display_channel_get_stream_id(DisplayChannel *display, Stream *stream);
 
diff --git a/server/red-worker.c b/server/red-worker.c
index a79a075..27ab8a2 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -590,9 +590,9 @@ static void handle_dev_destroy_surfaces(void *opaque, void *payload)
 static void red_worker_push_monitors_config(RedWorker *worker)
 {
     DisplayChannelClient *dcc;
-    GList *item, *next;
+    GListIter iter;
 
-    FOREACH_DCC(worker->display_channel, item, next, dcc) {
+    FOREACH_DCC(worker->display_channel, iter, dcc) {
         dcc_push_monitors_config(dcc);
     }
 }
diff --git a/server/stream.c b/server/stream.c
index 4c6621c..9d878c8 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -96,13 +96,13 @@ static RedPipeItem *stream_destroy_item_new(StreamAgent *agent)
 void stream_stop(DisplayChannel *display, Stream *stream)
 {
     DisplayChannelClient *dcc;
-    GList *link, *next;
+    GListIter iter;
 
     spice_return_if_fail(ring_item_is_linked(&stream->link));
     spice_return_if_fail(!stream->current);
 
     spice_debug("stream %d", display_channel_get_stream_id(display, stream));
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         StreamAgent *stream_agent;
 
         stream_agent = dcc_get_stream_agent(dcc, display_channel_get_stream_id(display, stream));
@@ -279,7 +279,7 @@ static bool is_next_stream_frame(DisplayChannel *display,
 static void attach_stream(DisplayChannel *display, Drawable *drawable, Stream *stream)
 {
     DisplayChannelClient *dcc;
-    GList *link, *next;
+    GListIter iter;
 
     spice_assert(drawable && stream);
     spice_assert(!drawable->stream && !stream->current);
@@ -298,7 +298,7 @@ static void attach_stream(DisplayChannel *display, Drawable *drawable, Stream *s
         stream->num_input_frames++;
     }
 
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         StreamAgent *agent;
         QRegion clip_in_draw_dest;
 
@@ -335,7 +335,7 @@ static void before_reattach_stream(DisplayChannel *display,
     int index;
     StreamAgent *agent;
     GList *dpi_link, *dpi_next;
-    GList *link, *link_next;
+    GListIter iter;
 
     spice_return_if_fail(stream->current);
 
@@ -374,7 +374,7 @@ static void before_reattach_stream(DisplayChannel *display,
     }
 
 
-    FOREACH_DCC(display, link, link_next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         double drop_factor;
 
         agent = dcc_get_stream_agent(dcc, index);
@@ -419,7 +419,7 @@ static Stream *display_channel_stream_try_new(DisplayChannel *display)
 static void display_channel_create_stream(DisplayChannel *display, Drawable *drawable)
 {
     DisplayChannelClient *dcc;
-    GList *link, *next;
+    GListIter iter;
     Stream *stream;
     SpiceRect* src_rect;
 
@@ -456,7 +456,7 @@ static void display_channel_create_stream(DisplayChannel *display, Drawable *dra
     stream->input_fps_start_time = drawable->creation_time;
     display->priv->streams_size_total += stream->width * stream->height;
     display->priv->stream_count++;
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         dcc_create_stream(dcc, stream);
     }
     spice_debug("stream %d %dx%d (%d, %d) (%d, %d) %u fps",
@@ -903,10 +903,10 @@ clear_vis_region:
 static void detach_stream_gracefully(DisplayChannel *display, Stream *stream,
                                      Drawable *update_area_limit)
 {
-    GList *link, *next;
+    GListIter iter;
     DisplayChannelClient *dcc;
 
-    FOREACH_DCC(display, link, next, dcc) {
+    FOREACH_DCC(display, iter, dcc) {
         dcc_detach_stream_gracefully(dcc, stream, update_area_limit);
     }
     if (stream->current) {
@@ -928,7 +928,7 @@ void stream_detach_behind(DisplayChannel *display, QRegion *region, Drawable *dr
 {
     Ring *ring = &display->priv->streams;
     RingItem *item = ring_get_head(ring);
-    GList *link, *next;
+    GListIter iter;
     DisplayChannelClient *dcc;
     bool is_connected = red_channel_is_connected(RED_CHANNEL(display));
 
@@ -937,7 +937,7 @@ void stream_detach_behind(DisplayChannel *display, QRegion *region, Drawable *dr
         int detach = 0;
         item = ring_next(ring, item);
 
-        FOREACH_DCC(display, link, next, dcc) {
+        FOREACH_DCC(display, iter, dcc) {
             StreamAgent *agent = dcc_get_stream_agent(dcc, display_channel_get_stream_id(display, stream));
 
             if (region_intersects(&agent->vis_region, region)) {
commit 9b5f93d1a70f069fb56affb7cf46ad56b756f75d
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Sep 20 08:42:27 2016 +0100

    Base FOREACH_CLIENT on GLIST_FOREACH
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/main-channel.c b/server/main-channel.c
index d176498..bf84694 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -44,10 +44,10 @@ static void main_channel_client_on_disconnect(RedChannelClient *rcc)
 
 RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t connection_id)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(main_chan, link, next, rcc) {
+    FOREACH_CLIENT(main_chan, iter, rcc) {
         MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
         if (main_channel_client_get_connection_id(mcc) == connection_id) {
             return red_channel_client_get_client(rcc);
@@ -334,10 +334,10 @@ MainChannel* main_channel_new(RedsState *reds)
 
 static int main_channel_connect_semi_seamless(MainChannel *main_channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(main_channel, link, next, rcc) {
+    FOREACH_CLIENT(main_channel, iter, rcc) {
         MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
         if (main_channel_client_connect_semi_seamless(mcc))
             main_channel->num_clients_mig_wait++;
@@ -347,12 +347,12 @@ static int main_channel_connect_semi_seamless(MainChannel *main_channel)
 
 static int main_channel_connect_seamless(MainChannel *main_channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
     spice_assert(g_list_length(main_channel->base.clients) == 1);
 
-    FOREACH_CLIENT(main_channel, link, next, rcc) {
+    FOREACH_CLIENT(main_channel, iter, rcc) {
         MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
         main_channel_client_connect_seamless(mcc);
         main_channel->num_clients_mig_wait++;
@@ -389,10 +389,10 @@ int main_channel_migrate_connect(MainChannel *main_channel, RedsMigSpice *mig_ta
 
 void main_channel_migrate_cancel_wait(MainChannel *main_chan)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(main_chan, link, next, rcc) {
+    FOREACH_CLIENT(main_chan, iter, rcc) {
         MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
         main_channel_client_migrate_cancel_wait(mcc);
     }
@@ -401,7 +401,7 @@ void main_channel_migrate_cancel_wait(MainChannel *main_chan)
 
 int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
 {
-    GList *link, *next;
+    GListIter iter;
     int semi_seamless_count = 0;
     RedChannelClient *rcc;
 
@@ -412,7 +412,7 @@ int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
         return 0;
     }
 
-    FOREACH_CLIENT(main_chan, link, next, rcc) {
+    FOREACH_CLIENT(main_chan, iter, rcc) {
         MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
         if (main_channel_client_migrate_src_complete(mcc, success))
             semi_seamless_count++;
diff --git a/server/red-channel.c b/server/red-channel.c
index 852065c..927e6e9 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -87,10 +87,10 @@ void red_channel_add_client(RedChannel *channel, RedChannelClient *rcc)
 
 int red_channel_test_remote_common_cap(RedChannel *channel, uint32_t cap)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (!red_channel_client_test_remote_common_cap(rcc, cap)) {
             return FALSE;
         }
@@ -100,10 +100,10 @@ int red_channel_test_remote_common_cap(RedChannel *channel, uint32_t cap)
 
 int red_channel_test_remote_cap(RedChannel *channel, uint32_t cap)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (!red_channel_client_test_remote_cap(rcc, cap)) {
             return FALSE;
         }
@@ -486,13 +486,13 @@ void red_channel_apply_clients_data(RedChannel *channel, channel_client_callback
 
 int red_channel_all_blocked(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
     if (!channel || !channel->clients) {
         return FALSE;
     }
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (!red_channel_client_is_blocked(rcc)) {
             return FALSE;
         }
@@ -502,10 +502,10 @@ int red_channel_all_blocked(RedChannel *channel)
 
 int red_channel_any_blocked(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (red_channel_client_is_blocked(rcc)) {
             return TRUE;
         }
@@ -529,10 +529,10 @@ int red_channel_get_first_socket(RedChannel *channel)
 
 int red_channel_no_item_being_sent(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (!red_channel_client_no_item_being_sent(rcc)) {
             return FALSE;
         }
@@ -740,7 +740,7 @@ static int red_channel_pipes_create_batch(RedChannel *channel,
                                 new_pipe_item_t creator, void *data,
                                 rcc_item_t pipe_add)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     RedPipeItem *item;
     int num = 0, n = 0;
@@ -748,7 +748,7 @@ static int red_channel_pipes_create_batch(RedChannel *channel,
     spice_assert(creator != NULL);
     spice_assert(pipe_add != NULL);
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         item = (*creator)(rcc, data, num++);
         if (item) {
             (*pipe_add)(rcc, item);
@@ -783,11 +783,11 @@ void red_channel_pipes_new_add_tail(RedChannel *channel, new_pipe_item_t creator
 
 uint32_t red_channel_max_pipe_size(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     uint32_t pipe_size = 0;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         uint32_t new_size;
         new_size = red_channel_client_get_pipe_size(rcc);
         pipe_size = MAX(pipe_size, new_size);
@@ -797,11 +797,11 @@ uint32_t red_channel_max_pipe_size(RedChannel *channel)
 
 uint32_t red_channel_min_pipe_size(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     uint32_t pipe_size = ~0;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         uint32_t new_size;
         new_size = red_channel_client_get_pipe_size(rcc);
         pipe_size = MIN(pipe_size, new_size);
@@ -811,11 +811,11 @@ uint32_t red_channel_min_pipe_size(RedChannel *channel)
 
 uint32_t red_channel_sum_pipes_size(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     uint32_t sum = 0;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         sum += red_channel_client_get_pipe_size(rcc);
     }
     return sum;
diff --git a/server/red-channel.h b/server/red-channel.h
index 68bfc7a..def5de0 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -250,15 +250,9 @@ struct RedChannel {
 #endif
 };
 
-#define FOREACH_CLIENT(channel, _link, _next, _data)                   \
-    for (_link = (channel ? RED_CHANNEL(channel)->clients : NULL), \
-         _next = (_link ? _link->next : NULL), \
-         _data = (_link ? _link->data : NULL); \
-         _link; \
-         _link = _next, \
-         _next = (_link ? _link->next : NULL), \
-         _data = (_link ? _link->data : NULL))
-
+#define FOREACH_CLIENT(_channel, _iter, _data) \
+    GLIST_FOREACH((_channel ? RED_CHANNEL(_channel)->clients : NULL), \
+                  _iter, RedChannelClient, _data)
 
 #define RED_CHANNEL(Channel) ((RedChannel *)(Channel))
 
diff --git a/server/red-worker.c b/server/red-worker.c
index fcd5d90..a79a075 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -481,7 +481,7 @@ static void guest_set_client_capabilities(RedWorker *worker)
 {
     int i;
     RedChannelClient *rcc;
-    GList *link, *next;
+    GListIter iter;
     uint8_t caps[SPICE_CAPABILITIES_SIZE] = { 0 };
     int caps_available[] = {
         SPICE_DISPLAY_CAP_SIZED_STREAM,
@@ -514,7 +514,7 @@ static void guest_set_client_capabilities(RedWorker *worker)
         for (i = 0 ; i < sizeof(caps_available) / sizeof(caps_available[0]); ++i) {
             SET_CAP(caps, caps_available[i]);
         }
-        FOREACH_CLIENT(worker->display_channel, link, next, rcc) {
+        FOREACH_CLIENT(worker->display_channel, iter, rcc) {
             for (i = 0 ; i < sizeof(caps_available) / sizeof(caps_available[0]); ++i) {
                 if (!red_channel_client_test_remote_cap(rcc, caps_available[i]))
                     CLEAR_CAP(caps, caps_available[i]);
commit 3fa2f12c1f2bdc6c30752b9aea80a3427d87cfae
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Sep 20 08:41:31 2016 +0100

    Use proper FOREACH_DCC instead of FOREACH_CLIENT
    
    FOREACH_DCC should be more DisplayChannel related.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/display-channel.c b/server/display-channel.c
index cd9c937..88a9ba3 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -196,7 +196,7 @@ void display_channel_surface_unref(DisplayChannel *display, uint32_t surface_id)
 
     region_destroy(&surface->draw_dirty_region);
     surface->context.canvas = NULL;
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         dcc_destroy_surface(dcc, surface_id);
     }
 
@@ -238,7 +238,7 @@ static void streams_update_visible_region(DisplayChannel *display, Drawable *dra
             continue;
         }
 
-        FOREACH_CLIENT(display, link, next, dcc) {
+        FOREACH_DCC(display, link, next, dcc) {
             agent = dcc_get_stream_agent(dcc, display_channel_get_stream_id(display, stream));
 
             if (region_intersects(&agent->vis_region, &drawable->tree_item.base.rgn)) {
@@ -256,7 +256,7 @@ static void pipes_add_drawable(DisplayChannel *display, Drawable *drawable)
     GList *link, *next;
 
     spice_warn_if_fail(drawable->pipes == NULL);
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         dcc_prepend_drawable(dcc, drawable);
     }
 }
@@ -283,7 +283,7 @@ static void pipes_add_drawable_after(DisplayChannel *display,
     if (num_other_linked != g_list_length(display->common.base.clients)) {
         GList *link, *next;
         spice_debug("TODO: not O(n^2)");
-        FOREACH_CLIENT(display, link, next, dcc) {
+        FOREACH_DCC(display, link, next, dcc) {
             int sent = 0;
             GList *l;
             for (l = pos_after->pipes; l != NULL; l = l->next) {
@@ -443,7 +443,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem *
              * (or will receive) other_drawable */
             dpi_item = g_list_first(other_drawable->pipes);
             /* dpi contains a sublist of dcc's, ordered the same */
-            FOREACH_CLIENT(display, link, next, dcc) {
+            FOREACH_DCC(display, link, next, dcc) {
                 if (dpi_item && dcc == ((RedDrawablePipeItem *) dpi_item->data)->dcc) {
                     dpi_item = dpi_item->next;
                 } else {
@@ -1168,7 +1168,7 @@ void display_channel_free_glz_drawables_to_free(DisplayChannel *display)
 
     spice_return_if_fail(display);
 
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         image_encoders_free_glz_drawables_to_free(dcc_get_encoders(dcc));
     }
 }
@@ -1180,7 +1180,7 @@ void display_channel_free_glz_drawables(DisplayChannel *display)
 
     spice_return_if_fail(display);
 
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         image_encoders_free_glz_drawables(dcc_get_encoders(dcc));
     }
 }
@@ -1223,7 +1223,7 @@ void display_channel_free_some(DisplayChannel *display)
 
     spice_debug("#draw=%d, #glz_draw=%d", display->priv->drawable_count,
                 display->priv->encoder_shared_data.glz_drawable_count);
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         ImageEncoders *encoders = dcc_get_encoders(dcc);
 
         // encoding using the dictionary is prevented since the following operations might
@@ -1237,7 +1237,7 @@ void display_channel_free_some(DisplayChannel *display)
         free_one_drawable(display, TRUE);
     }
 
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         ImageEncoders *encoders = dcc_get_encoders(dcc);
 
         image_encoders_glz_encode_unlock(encoders);
@@ -1706,7 +1706,7 @@ static void clear_surface_drawables_from_pipes(DisplayChannel *display, int surf
     GList *link, *next;
     DisplayChannelClient *dcc;
 
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         if (!dcc_clear_surface_drawables_from_pipe(dcc, surface_id, wait_if_used)) {
             red_channel_client_disconnect(RED_CHANNEL_CLIENT(dcc));
         }
@@ -1772,7 +1772,7 @@ static void send_create_surface(DisplayChannel *display, int surface_id, int ima
     DisplayChannelClient *dcc;
     GList *link, *next;
 
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         dcc_create_surface(dcc, surface_id);
         if (image_ready)
             dcc_push_surface_image(dcc, surface_id);
diff --git a/server/red-worker.c b/server/red-worker.c
index 62e5d86..fcd5d90 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -592,7 +592,7 @@ static void red_worker_push_monitors_config(RedWorker *worker)
     DisplayChannelClient *dcc;
     GList *item, *next;
 
-    FOREACH_CLIENT(worker->display_channel, item, next, dcc) {
+    FOREACH_DCC(worker->display_channel, item, next, dcc) {
         dcc_push_monitors_config(dcc);
     }
 }
diff --git a/server/stream.c b/server/stream.c
index 49b5910..4c6621c 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -102,7 +102,7 @@ void stream_stop(DisplayChannel *display, Stream *stream)
     spice_return_if_fail(!stream->current);
 
     spice_debug("stream %d", display_channel_get_stream_id(display, stream));
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         StreamAgent *stream_agent;
 
         stream_agent = dcc_get_stream_agent(dcc, display_channel_get_stream_id(display, stream));
@@ -298,7 +298,7 @@ static void attach_stream(DisplayChannel *display, Drawable *drawable, Stream *s
         stream->num_input_frames++;
     }
 
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         StreamAgent *agent;
         QRegion clip_in_draw_dest;
 
@@ -374,7 +374,7 @@ static void before_reattach_stream(DisplayChannel *display,
     }
 
 
-    FOREACH_CLIENT(display, link, link_next, dcc) {
+    FOREACH_DCC(display, link, link_next, dcc) {
         double drop_factor;
 
         agent = dcc_get_stream_agent(dcc, index);
@@ -456,7 +456,7 @@ static void display_channel_create_stream(DisplayChannel *display, Drawable *dra
     stream->input_fps_start_time = drawable->creation_time;
     display->priv->streams_size_total += stream->width * stream->height;
     display->priv->stream_count++;
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         dcc_create_stream(dcc, stream);
     }
     spice_debug("stream %d %dx%d (%d, %d) (%d, %d) %u fps",
@@ -906,7 +906,7 @@ static void detach_stream_gracefully(DisplayChannel *display, Stream *stream,
     GList *link, *next;
     DisplayChannelClient *dcc;
 
-    FOREACH_CLIENT(display, link, next, dcc) {
+    FOREACH_DCC(display, link, next, dcc) {
         dcc_detach_stream_gracefully(dcc, stream, update_area_limit);
     }
     if (stream->current) {
@@ -937,7 +937,7 @@ void stream_detach_behind(DisplayChannel *display, QRegion *region, Drawable *dr
         int detach = 0;
         item = ring_next(ring, item);
 
-        FOREACH_CLIENT(display, link, next, dcc) {
+        FOREACH_DCC(display, link, next, dcc) {
             StreamAgent *agent = dcc_get_stream_agent(dcc, display_channel_get_stream_id(display, stream));
 
             if (region_intersects(&agent->vis_region, region)) {
commit 545ba23e184696a8f10066db5b2eb31e8eea0661
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Sep 20 08:15:18 2016 +0100

    RedChannel: Use more FOREACH_CLIENT macro
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/red-channel.c b/server/red-channel.c
index 6be160b..852065c 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -486,14 +486,13 @@ void red_channel_apply_clients_data(RedChannel *channel, channel_client_callback
 
 int red_channel_all_blocked(RedChannel *channel)
 {
-    GList *link;
+    GList *link, *next;
     RedChannelClient *rcc;
 
     if (!channel || !channel->clients) {
         return FALSE;
     }
-    for (link = channel->clients; link != NULL; link = link->next) {
-        rcc = link->data;
+    FOREACH_CLIENT(channel, link, next, rcc) {
         if (!red_channel_client_is_blocked(rcc)) {
             return FALSE;
         }
@@ -784,13 +783,12 @@ void red_channel_pipes_new_add_tail(RedChannel *channel, new_pipe_item_t creator
 
 uint32_t red_channel_max_pipe_size(RedChannel *channel)
 {
-    GList *link;
+    GList *link, *next;
     RedChannelClient *rcc;
     uint32_t pipe_size = 0;
 
-    for (link = channel->clients; link != NULL; link = link->next) {
+    FOREACH_CLIENT(channel, link, next, rcc) {
         uint32_t new_size;
-        rcc = link->data;
         new_size = red_channel_client_get_pipe_size(rcc);
         pipe_size = MAX(pipe_size, new_size);
     }
commit eabafbd09f1e2bc0fae15266ea12eb7f177935c2
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Sep 20 13:39:55 2016 +0100

    RedChannel: Add FOREACH_CHANNEL_CLIENT and use it to iterate
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/red-channel.c b/server/red-channel.c
index 474fe68..6be160b 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -31,6 +31,9 @@
 #include "main-dispatcher.h"
 #include "utils.h"
 
+#define FOREACH_CHANNEL_CLIENT(_client, _iter, _data) \
+    GLIST_FOREACH((_client ? (_client)->channels : NULL), _iter, RedChannelClient, _data)
+
 /*
  * Lifetime of RedChannel, RedChannelClient and RedClient:
  * RedChannel is created and destroyed by the calls to
@@ -577,14 +580,16 @@ RedClient *red_client_unref(RedClient *client)
 
 void red_client_set_migration_seamless(RedClient *client) // dest
 {
-    GList *link;
+    GListIter iter;
+    RedChannelClient *rcc;
+
     spice_assert(client->during_target_migrate);
     pthread_mutex_lock(&client->lock);
     client->seamless_migrate = TRUE;
     /* update channel clients that got connected before the migration
      * type was set. red_client_add_channel will handle newer channel clients */
-    for (link = client->channels; link != NULL; link = link->next) {
-        if (red_channel_client_set_migration_seamless(link->data))
+    FOREACH_CHANNEL_CLIENT(client, iter, rcc) {
+        if (red_channel_client_set_migration_seamless(rcc))
             client->num_migrated_channels++;
     }
     pthread_mutex_unlock(&client->lock);
@@ -592,7 +597,7 @@ void red_client_set_migration_seamless(RedClient *client) // dest
 
 void red_client_migrate(RedClient *client)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     RedChannel *channel;
 
@@ -603,21 +608,17 @@ void red_client_migrate(RedClient *client)
                       " this might be a BUG",
                       client->thread_id, pthread_self());
     }
-    link = client->channels;
-    while (link) {
-        next = link->next;
-        rcc = link->data;
+    FOREACH_CHANNEL_CLIENT(client, iter, rcc) {
         channel = red_channel_client_get_channel(rcc);
         if (red_channel_client_is_connected(rcc)) {
             channel->client_cbs.migrate(rcc);
         }
-        link = next;
     }
 }
 
 void red_client_destroy(RedClient *client)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
     spice_printerr("destroy client %p with #channels=%d", client, g_list_length(client->channels));
@@ -628,13 +629,10 @@ void red_client_destroy(RedClient *client)
                       client->thread_id,
                       pthread_self());
     }
-    link = client->channels;
-    while (link) {
+    FOREACH_CHANNEL_CLIENT(client, iter, rcc) {
         RedChannel *channel;
-        next = link->next;
         // some channels may be in other threads, so disconnection
         // is not synchronous.
-        rcc = link->data;
         channel = red_channel_client_get_channel(rcc);
         red_channel_client_set_destroying(rcc);
         // some channels may be in other threads. However we currently
@@ -646,7 +644,6 @@ void red_client_destroy(RedClient *client)
         spice_assert(red_channel_client_pipe_is_empty(rcc));
         spice_assert(red_channel_client_no_item_being_sent(rcc));
         red_channel_client_destroy(rcc);
-        link = next;
     }
     red_client_unref(client);
 }
@@ -654,13 +651,12 @@ void red_client_destroy(RedClient *client)
 /* client->lock should be locked */
 RedChannelClient *red_client_get_channel(RedClient *client, int type, int id)
 {
-    GList *link;
+    GListIter iter;
     RedChannelClient *rcc;
     RedChannelClient *ret = NULL;
 
-    for (link = client->channels; link != NULL; link = link->next) {
+    FOREACH_CHANNEL_CLIENT(client, iter, rcc) {
         RedChannel *channel;
-        rcc = link->data;
         channel = red_channel_client_get_channel(rcc);
         if (channel->type == type && channel->id == id) {
             ret = rcc;
@@ -691,7 +687,8 @@ void red_client_set_main(RedClient *client, MainChannelClient *mcc) {
 
 void red_client_semi_seamless_migrate_complete(RedClient *client)
 {
-    GList *link, *next;
+    GListIter iter;
+    RedChannelClient *rcc;
 
     pthread_mutex_lock(&client->lock);
     if (!client->during_target_migrate || client->seamless_migrate) {
@@ -700,11 +697,8 @@ void red_client_semi_seamless_migrate_complete(RedClient *client)
         return;
     }
     client->during_target_migrate = FALSE;
-    link = client->channels;
-    while (link) {
-        next = link->next;
-        red_channel_client_semi_seamless_migration_complete(link->data);
-        link = next;
+    FOREACH_CHANNEL_CLIENT(client, iter, rcc) {
+        red_channel_client_semi_seamless_migration_complete(rcc);
     }
     pthread_mutex_unlock(&client->lock);
     reds_on_client_semi_seamless_migrate_complete(client->reds, client);
commit f1d593b02516a139c5f75e96f6ecbc350c188339
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Sep 16 16:02:40 2016 +0100

    Introduce some macros to simplify iteration on GList
    
    Noting that coding by hand these loop introduced some regression
    I'm trying to introduce back from macros.
    Before trying something harder to make possible to bind the type of
    the content I'm trying some simple macro as were before.
    I added the type to avoid some blindly void* casts.
    Also the GListIter is introduced to avoid the possibility to exchange
    easily some parameters.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/red-common.h b/server/red-common.h
index 7ab7e15..190fd9c 100644
--- a/server/red-common.h
+++ b/server/red-common.h
@@ -62,4 +62,22 @@ extern const SpiceCoreInterfaceInternal event_loop_core;
 
 typedef struct RedsState RedsState;
 
+typedef struct GListIter {
+    GList *link;
+    GList *next;
+} GListIter;
+
+#define GLIST_FOREACH_GENERIC(_list, _iter, _type, _data, _dir) \
+    for (_iter.link = _list; \
+        (_data = (_type *) (_iter.link ? _iter.link->data : NULL), \
+         _iter.next = (_iter.link ? _iter.link->_dir : NULL), \
+         _iter.link) != NULL; \
+         _iter.link = _iter.next)
+
+#define GLIST_FOREACH(_list, _iter, _type, _data) \
+    GLIST_FOREACH_GENERIC(_list, _iter, _type, _data, next)
+
+#define GLIST_FOREACH_REVERSED(_list, _iter, _type, _data) \
+    GLIST_FOREACH_GENERIC(_list, _iter, _type, _data, prev)
+
 #endif
diff --git a/server/reds-private.h b/server/reds-private.h
index 29645bf..a044a57 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -156,4 +156,7 @@ struct RedsState {
     MainDispatcher *main_dispatcher;
 };
 
+#define FOREACH_QXL_INSTANCE(_reds, _iter, _qxl) \
+    GLIST_FOREACH(_reds->qxl_instances, _iter, QXLInstance, _qxl)
+
 #endif
diff --git a/server/reds.c b/server/reds.c
index 6244e32..5463700 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -688,15 +688,15 @@ int reds_get_mouse_mode(RedsState *reds)
 
 static void reds_set_mouse_mode(RedsState *reds, uint32_t mode)
 {
-    GList *l;
+    GListIter it;
+    QXLInstance *qxl;
 
     if (reds->mouse_mode == mode) {
         return;
     }
     reds->mouse_mode = mode;
 
-    for (l = reds->qxl_instances; l != NULL; l = l->next) {
-        QXLInstance *qxl = (QXLInstance *)l->data;
+    FOREACH_QXL_INSTANCE(reds, it, qxl) {
         red_qxl_set_mouse_mode(qxl, mode);
     }
 
@@ -1717,14 +1717,11 @@ static void reds_mig_target_client_free(RedsState *reds, RedsMigTargetClient *mi
 
 static void reds_mig_target_client_disconnect_all(RedsState *reds)
 {
-    GList *l, *next;
+    GListIter it;
+    RedsMigTargetClient *mig_client;
 
-    l = reds->mig_target_clients;
-    while (l) {
-        next = l->next;
-        RedsMigTargetClient *mig_client = l->data;
+    GLIST_FOREACH(reds->mig_target_clients, it, RedsMigTargetClient, mig_client) {
         reds_client_disconnect(reds, mig_client->client);
-        l = next;
     }
 }
 
@@ -4315,13 +4312,14 @@ void reds_update_client_mouse_allowed(RedsState *reds)
     int allow_now = FALSE;
     int x_res = 0;
     int y_res = 0;
-    GList *l;
     int num_active_workers = g_list_length(reds->qxl_instances);
 
     if (num_active_workers > 0) {
+        GListIter it;
+        QXLInstance *qxl;
+
         allow_now = TRUE;
-        for (l = reds->qxl_instances; l != NULL && allow_now; l = l->next) {
-            QXLInstance *qxl = l->data;
+        FOREACH_QXL_INSTANCE(reds, it, qxl) {
             if (red_qxl_get_primary_active(qxl)) {
                 allow_now = red_qxl_get_allow_client_mouse(qxl, &x_res, &y_res);
                 break;
@@ -4342,15 +4340,14 @@ void reds_update_client_mouse_allowed(RedsState *reds)
 
 static gboolean reds_use_client_monitors_config(RedsState *reds)
 {
-    GList *l;
+    GListIter it;
+    QXLInstance *qxl;
 
     if (reds->qxl_instances == NULL) {
         return FALSE;
     }
 
-    for (l = reds->qxl_instances; l != NULL ; l = l->next) {
-        QXLInstance *qxl = l->data;
-
+    FOREACH_QXL_INSTANCE(reds, it, qxl) {
         if (!red_qxl_use_client_monitors_config(qxl))
             return FALSE;
     }
@@ -4359,10 +4356,10 @@ static gboolean reds_use_client_monitors_config(RedsState *reds)
 
 static void reds_client_monitors_config(RedsState *reds, VDAgentMonitorsConfig *monitors_config)
 {
-    GList *l;
+    GListIter it;
+    QXLInstance *qxl;
 
-    for (l = reds->qxl_instances; l != NULL; l = l->next) {
-        QXLInstance *qxl = l->data;
+    FOREACH_QXL_INSTANCE(reds, it, qxl) {
         if (!red_qxl_client_monitors_config(qxl, monitors_config)) {
             /* this is a normal condition, some qemu devices might not implement it */
             spice_debug("QXLInterface::client_monitors_config failed\n");
@@ -4385,10 +4382,10 @@ static int calc_compression_level(RedsState *reds)
 void reds_on_ic_change(RedsState *reds)
 {
     int compression_level = calc_compression_level(reds);
-    GList *l;
+    GListIter it;
+    QXLInstance *qxl;
 
-    for (l = reds->qxl_instances; l != NULL; l = l->next) {
-        QXLInstance *qxl = l->data;
+    FOREACH_QXL_INSTANCE(reds, it, qxl) {
         red_qxl_set_compression_level(qxl, compression_level);
         red_qxl_on_ic_change(qxl, spice_server_get_image_compression(reds));
     }
@@ -4397,10 +4394,10 @@ void reds_on_ic_change(RedsState *reds)
 void reds_on_sv_change(RedsState *reds)
 {
     int compression_level = calc_compression_level(reds);
-    GList *l;
+    GListIter it;
+    QXLInstance *qxl;
 
-    for (l = reds->qxl_instances; l != NULL; l = l->next) {
-        QXLInstance *qxl = l->data;
+    FOREACH_QXL_INSTANCE(reds, it, qxl) {
         red_qxl_set_compression_level(qxl, compression_level);
         red_qxl_on_sv_change(qxl, reds_get_streaming_video(reds));
     }
@@ -4408,29 +4405,30 @@ void reds_on_sv_change(RedsState *reds)
 
 void reds_on_vc_change(RedsState *reds)
 {
-    GList *l;
+    GListIter it;
+    QXLInstance *qxl;
 
-    for (l = reds->qxl_instances; l != NULL; l = l->next) {
-        red_qxl_on_vc_change(l->data, reds_get_video_codecs(reds));
+    FOREACH_QXL_INSTANCE(reds, it, qxl) {
+        red_qxl_on_vc_change(qxl, reds_get_video_codecs(reds));
     }
 }
 
 void reds_on_vm_stop(RedsState *reds)
 {
-    GList *l;
+    GListIter it;
+    QXLInstance *qxl;
 
-    for (l = reds->qxl_instances; l != NULL; l = l->next) {
-        QXLInstance *qxl = l->data;
+    FOREACH_QXL_INSTANCE(reds, it, qxl) {
         red_qxl_stop(qxl);
     }
 }
 
 void reds_on_vm_start(RedsState *reds)
 {
-    GList *l;
+    GListIter it;
+    QXLInstance *qxl;
 
-    for (l = reds->qxl_instances; l != NULL; l = l->next) {
-        QXLInstance *qxl = l->data;
+    FOREACH_QXL_INSTANCE(reds, it, qxl) {
         red_qxl_start(qxl);
     }
 }


More information about the Spice-commits mailing list