[Spice-devel] [PATCH spice-gtk 1/2] build: fix build with glib < 2.32

Marc-André Lureau marcandre.lureau at gmail.com
Fri Mar 16 09:13:48 PDT 2012


Using GMutex as a static mutex is only possible since 2.32.
---
 gtk/spice-channel-priv.h |    8 +++++++-
 gtk/spice-channel.c      |   20 ++++++++++----------
 gtk/spice-util-priv.h    |   14 ++++++++++++++
 3 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index 88611d0..c61779d 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -29,6 +29,7 @@
 #include <sasl/sasl.h>
 #endif
 
+#include "spice-util-priv.h"
 #include "coroutine.h"
 #include "gio-coroutine.h"
 
@@ -100,7 +101,7 @@ struct _SpiceChannelPrivate {
 
     GQueue                      xmit_queue;
     gboolean                    xmit_queue_blocked;
-    GMutex                      xmit_queue_lock;
+    STATIC_MUTEX                xmit_queue_lock;
     guint                       xmit_queue_wakeup_id;
 
     char                        name[16];
@@ -132,6 +133,11 @@ struct _SpiceChannelPrivate {
     uint64_t                    last_message_serial;
 };
 
+#if GLIB_CHECK_VERSION(2,32,0)
+#define g_mutex_lock(m) g_mutex_lock(&(m))
+#else
+#endif
+
 SpiceMsgIn *spice_msg_in_new(SpiceChannel *channel);
 SpiceMsgIn *spice_msg_in_sub_new(SpiceChannel *channel, SpiceMsgIn *parent,
                                    SpiceSubMessage *sub);
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index be95f00..0b7dff8 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -110,7 +110,7 @@ static void spice_channel_init(SpiceChannel *channel)
     spice_channel_set_common_capability(channel, SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION);
     spice_channel_set_common_capability(channel, SPICE_COMMON_CAP_MINI_HEADER);
     g_queue_init(&c->xmit_queue);
-    g_mutex_init(&c->xmit_queue_lock);
+    STATIC_MUTEX_INIT(c->xmit_queue_lock);
 }
 
 static void spice_channel_constructed(GObject *gobject)
@@ -162,7 +162,7 @@ static void spice_channel_finalize(GObject *gobject)
 
     g_idle_remove_by_data(gobject);
 
-    g_mutex_clear(&c->xmit_queue_lock);
+    STATIC_MUTEX_CLEAR(c->xmit_queue_lock);
 
     if (c->caps)
         g_array_free(c->caps, TRUE);
@@ -667,9 +667,9 @@ static gboolean spice_channel_idle_wakeup(gpointer user_data)
      *   5) xmit_queue_wakeup_id now says there is a wakeup pending which is
      *      false
      */
-    g_mutex_lock(&c->xmit_queue_lock);
+    STATIC_MUTEX_LOCK(c->xmit_queue_lock);
     c->xmit_queue_wakeup_id = 0;
-    g_mutex_unlock(&c->xmit_queue_lock);
+    STATIC_MUTEX_UNLOCK(c->xmit_queue_lock);
 
     spice_channel_wakeup(channel, FALSE);
 
@@ -685,7 +685,7 @@ void spice_msg_out_send(SpiceMsgOut *out)
     g_return_if_fail(out != NULL);
     g_return_if_fail(out->channel != NULL);
 
-    g_mutex_lock(&out->channel->priv->xmit_queue_lock);
+    STATIC_MUTEX_LOCK(out->channel->priv->xmit_queue_lock);
     if (out->channel->priv->xmit_queue_blocked) {
         g_warning("message queue is blocked, dropping message");
         goto end;
@@ -705,7 +705,7 @@ void spice_msg_out_send(SpiceMsgOut *out)
     }
 
 end:
-    g_mutex_unlock(&out->channel->priv->xmit_queue_lock);
+    STATIC_MUTEX_UNLOCK(out->channel->priv->xmit_queue_lock);
 }
 
 /* coroutine context */
@@ -1972,9 +1972,9 @@ static void spice_channel_iterate_write(SpiceChannel *channel)
     SpiceMsgOut *out;
 
     do {
-        g_mutex_lock(&c->xmit_queue_lock);
+        STATIC_MUTEX_LOCK(c->xmit_queue_lock);
         out = g_queue_pop_head(&c->xmit_queue);
-        g_mutex_unlock(&c->xmit_queue_lock);
+        STATIC_MUTEX_UNLOCK(c->xmit_queue_lock);
         if (out)
             spice_channel_write_msg(channel, out);
     } while (out);
@@ -2373,7 +2373,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
     c->peer_msg = NULL;
     c->peer_pos = 0;
 
-    g_mutex_lock(&c->xmit_queue_lock);
+    STATIC_MUTEX_LOCK(c->xmit_queue_lock);
     c->xmit_queue_blocked = TRUE; /* Disallow queuing new messages */
     g_queue_foreach(&c->xmit_queue, (GFunc)spice_msg_out_unref, NULL);
     g_queue_clear(&c->xmit_queue);
@@ -2381,7 +2381,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
         g_source_remove(c->xmit_queue_wakeup_id);
         c->xmit_queue_wakeup_id = 0;
     }
-    g_mutex_unlock(&c->xmit_queue_lock);
+    STATIC_MUTEX_UNLOCK(c->xmit_queue_lock);
 
     g_array_set_size(c->remote_common_caps, 0);
     g_array_set_size(c->remote_caps, 0);
diff --git a/gtk/spice-util-priv.h b/gtk/spice-util-priv.h
index 4d52100..1be0edf 100644
--- a/gtk/spice-util-priv.h
+++ b/gtk/spice-util-priv.h
@@ -27,6 +27,20 @@ G_BEGIN_DECLS
 gboolean spice_strv_contains(const GStrv strv, const gchar *str);
 gchar* spice_uuid_to_string(const guint8 uuid[16]);
 
+#if GLIB_CHECK_VERSION(2,32,0)
+#define STATIC_MUTEX            GMutex
+#define STATIC_MUTEX_INIT(m)    g_mutex_init(&(m))
+#define STATIC_MUTEX_CLEAR(m)   g_mutex_clear(&(m))
+#define STATIC_MUTEX_LOCK(m)    g_mutex_lock(&(m))
+#define STATIC_MUTEX_UNLOCK(m)  g_mutex_unlock(&(m))
+#else
+#define STATIC_MUTEX            GStaticMutex
+#define STATIC_MUTEX_INIT(m)    g_static_mutex_init(&(m))
+#define STATIC_MUTEX_CLEAR(m)   g_static_mutex_free(&(m))
+#define STATIC_MUTEX_LOCK(m)    g_static_mutex_lock(&(m))
+#define STATIC_MUTEX_UNLOCK(m)  g_static_mutex_unlock(&(m))
+#endif
+
 G_END_DECLS
 
 #endif /* SPICE_UTIL_PRIV_H */
-- 
1.7.7.6



More information about the Spice-devel mailing list