[telepathy-gabble/master] request pipeline: cancel idle callback when pipeline is freed

Dafydd Harries dafydd.harries at collabora.co.uk
Wed Aug 12 11:14:40 PDT 2009


---
 src/request-pipeline.c |    3 ++-
 src/util.c             |   21 +++++++++++++++++++++
 src/util.h             |    1 +
 3 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/src/request-pipeline.c b/src/request-pipeline.c
index 7d3c0a4..f533c4a 100644
--- a/src/request-pipeline.c
+++ b/src/request-pipeline.c
@@ -27,6 +27,7 @@
 
 #include "connection.h"
 #include "debug.h"
+#include "util.h"
 
 #define DEFAULT_REQUEST_TIMEOUT 20000
 #define REQUEST_PIPELINE_SIZE 5
@@ -405,7 +406,7 @@ gabble_request_pipeline_enqueue (GabbleRequestPipeline *pipeline,
    * there's an error, the callback will be called after this function returns.
    */
   if (g_slist_length (priv->items_in_flight) < REQUEST_PIPELINE_SIZE)
-    g_idle_add (delayed_run_pipeline, pipeline);
+    gabble_idle_add_weak (delayed_run_pipeline, G_OBJECT (pipeline));
 
   return item;
 }
diff --git a/src/util.c b/src/util.c
index 25b35be..2d1167d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1012,6 +1012,27 @@ gabble_signal_connect_weak (gpointer instance,
   g_object_weak_ref (user_data, user_data_destroyed_cb, ctx);
 }
 
+static void
+idle_cancel (gpointer data,
+             GObject *dead_object)
+{
+  g_source_remove (GPOINTER_TO_UINT (data));
+}
+
+/* Like g_idle_add(), but cancel the callback if the provided object is
+ * finalized.
+ */
+guint
+gabble_idle_add_weak (GSourceFunc function,
+                      GObject *object)
+{
+  guint id;
+
+  id = g_idle_add (function, object);
+  g_object_weak_ref (object, idle_cancel, GUINT_TO_POINTER (id));
+  return id;
+}
+
 typedef struct {
     gchar *key;
     gchar *value;
diff --git a/src/util.h b/src/util.h
index 7e7138a..e2695b1 100644
--- a/src/util.h
+++ b/src/util.h
@@ -87,6 +87,7 @@ lm_iq_message_make_result (LmMessage *iq_message);
 
 void gabble_signal_connect_weak (gpointer instance, const gchar *detailed_signal,
     GCallback c_handler, GObject *user_data);
+guint gabble_idle_add_weak (GSourceFunc function, GObject *object);
 
 const gchar * lm_message_node_get_attribute_with_namespace (LmMessageNode *node,
     const gchar *attribute,
-- 
1.5.6.5




More information about the telepathy-commits mailing list