[Spice-commits] 2 commits - gtk/channel-base.c gtk/channel-display.c gtk/spice-channel.c gtk/spice-channel-priv.h gtk/spice-session.c gtk/spice-session-priv.h

Marc-André Lureau elmarco at kemper.freedesktop.org
Sun Jan 8 04:53:35 PST 2012


 gtk/channel-base.c       |   39 ++++++++++++++++++++++++++++++++++++---
 gtk/channel-display.c    |    2 ++
 gtk/spice-channel-priv.h |    1 +
 gtk/spice-channel.c      |    2 ++
 gtk/spice-session-priv.h |    1 +
 gtk/spice-session.c      |   11 +++++------
 6 files changed, 47 insertions(+), 9 deletions(-)

New commits:
commit 506a080fd50136c757d166e83bf541eda01dd1ae
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Wed Jan 4 16:05:21 2012 +0100

    Wait for channels before invalidating images
    
    https://bugs.freedesktop.org/show_bug.cgi?id=44179

diff --git a/gtk/channel-display.c b/gtk/channel-display.c
index 08e3e16..d5061da 100644
--- a/gtk/channel-display.c
+++ b/gtk/channel-display.c
@@ -863,6 +863,8 @@ static void display_handle_inv_list(SpiceChannel *channel, SpiceMsgIn *in)
 /* coroutine context */
 static void display_handle_inv_pixmap_all(SpiceChannel *channel, SpiceMsgIn *in)
 {
+    spice_channel_handle_wait_for_channels(channel, in);
+
     spice_session_images_clear(spice_channel_get_session(channel));
 }
 
commit 049cea8d4cdda1f35a09e436cfa25270210bc8b6
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Wed Jan 4 15:06:13 2012 +0100

    Implement SPICE_MSG_WAIT_FOR_CHANNELS
    
    https://bugs.freedesktop.org/show_bug.cgi?id=44179

diff --git a/gtk/channel-base.c b/gtk/channel-base.c
index a6a2892..54232ef 100644
--- a/gtk/channel-base.c
+++ b/gtk/channel-base.c
@@ -90,14 +90,47 @@ void spice_channel_handle_disconnect(SpiceChannel *channel, SpiceMsgIn *in)
                 disconnect->time_stamp, disconnect->reason);
 }
 
+typedef struct WaitForChannelData
+{
+    SpiceWaitForChannel *wait;
+    SpiceChannel *channel;
+} WaitForChannelData;
+
+/* coroutine and main context */
+static gboolean wait_for_channel(gpointer data)
+{
+    WaitForChannelData *wfc = data;
+    SpiceChannelPrivate *c = wfc->channel->priv;
+    SpiceChannel *wait_channel;
+
+    wait_channel = spice_session_lookup_channel(c->session, wfc->wait->channel_id, wfc->wait->channel_type);
+    g_return_val_if_fail(wait_channel != NULL, TRUE);
+
+    if (wait_channel->priv->last_message_serial >= wfc->wait->message_serial)
+        return TRUE;
+
+    return FALSE;
+}
+
 /* coroutine context */
 G_GNUC_INTERNAL
 void spice_channel_handle_wait_for_channels(SpiceChannel *channel, SpiceMsgIn *in)
 {
-    /* SpiceChannelPrivate *c = channel->priv;
-       SpiceMsgWaitForChannels *wfc = spice_msg_in_parsed(in); */
+    SpiceMsgWaitForChannels *wfc = spice_msg_in_parsed(in);
+    int i;
+
+    g_return_if_fail(in->header.size >= sizeof(*wfc) + wfc->wait_count * sizeof(wfc->wait_list[0]));
 
-    SPICE_DEBUG("%s TODO", __FUNCTION__);
+    for (i = 0; i < wfc->wait_count; ++i) {
+        WaitForChannelData data = {
+            .wait = wfc->wait_list + i,
+            .channel = channel
+        };
+
+        SPICE_DEBUG("waiting for serial %lu (%d/%d)", data.wait->message_serial, i + 1, wfc->wait_count);
+        g_condition_wait(wait_for_channel, &data);
+        SPICE_DEBUG("waiting for serial %lu, done", data.wait->message_serial);
+    }
 }
 
 static void
diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index df35e4c..ea510c7 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -126,6 +126,7 @@ struct _SpiceChannelPrivate {
     GArray                      *remote_common_caps;
 
     gsize                       total_read_bytes;
+    uint64_t                    last_message_serial;
 };
 
 SpiceMsgIn *spice_msg_in_new(SpiceChannel *channel);
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 079028a..04af87d 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -1680,6 +1680,8 @@ void spice_channel_recv_msg(SpiceChannel *channel,
     msg_handler(channel, in, data);
 
 end:
+    c->last_message_serial = in->header.serial;
+
     /* release message */
     c->msg_in = NULL;
     spice_msg_in_unref(in);
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 4d52254..bb5ae9b 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -127,6 +127,7 @@ void spice_session_palettes_clear(SpiceSession *session);
 void spice_session_images_clear(SpiceSession *session);
 void spice_session_migrate_end(SpiceSession *session);
 gboolean spice_session_migrate_after_main_init(SpiceSession *session);
+SpiceChannel* spice_session_lookup_channel(SpiceSession *session, gint id, gint type);
 
 G_END_DECLS
 
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 1199caf..be6753a 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -1086,8 +1086,7 @@ void spice_session_set_migration(SpiceSession *session, SpiceSession *migration)
 }
 
 G_GNUC_INTERNAL
-SpiceChannel* get_channel_by_id_and_type(SpiceSession *session,
-                                         gint id, gint type)
+SpiceChannel* spice_session_lookup_channel(SpiceSession *session, gint id, gint type)
 {
     RingItem *ring, *next;
     SpiceSessionPrivate *s = session->priv;
@@ -1132,9 +1131,9 @@ void spice_session_abort_migration(SpiceSession *session)
             continue;
 
         spice_channel_swap(c->channel,
-            get_channel_by_id_and_type(s->migration,
-                                       spice_channel_get_channel_id(c->channel),
-                                       spice_channel_get_channel_type(c->channel)));
+            spice_session_lookup_channel(s->migration,
+                                         spice_channel_get_channel_id(c->channel),
+                                         spice_channel_get_channel_type(c->channel)));
     }
 
     g_list_free(s->migration_left);
@@ -1161,7 +1160,7 @@ void spice_session_channel_migrate(SpiceSession *session, SpiceChannel *channel)
     type = spice_channel_get_channel_type(channel);
     SPICE_DEBUG("migrating channel id:%d type:%d", id, type);
 
-    c = get_channel_by_id_and_type(s->migration, id, type);
+    c = spice_session_lookup_channel(s->migration, id, type);
     g_return_if_fail(c != NULL);
 
     spice_channel_swap(channel, c);


More information about the Spice-commits mailing list