[libgdata] core: Emit notifications from GDataDownloadStream in the download thread



commit d08105e42c0f6d93dfff9fd5e61fe9522579cdb6
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Dec 9 19:54:58 2010 +0000

    core: Emit notifications from GDataDownloadStream in the download thread
    
    Emitting them in the main thread doesn't guarantee us any extra thread
    safety (the client is still required to be MT-safe, as the thread which
    started the download operation could be different from the one with the
    main loop), and can cause memory leaks if a main loop isn't running.
    
    Note that this is an API break (of sorts), as extra restrictions have been
    added to the use of notification signals for
    GDataDownloadStream::content-length and GDataDownloadStream::content-type.

 gdata/gdata-download-stream.c |   28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/gdata/gdata-download-stream.c b/gdata/gdata-download-stream.c
index 09712a1..9b74efd 100644
--- a/gdata/gdata-download-stream.c
+++ b/gdata/gdata-download-stream.c
@@ -138,6 +138,10 @@ gdata_download_stream_class_init (GDataDownloadStreamClass *klass)
 	 *
 	 * The content type of the file being downloaded.
 	 *
+	 * Note that change notifications for this property (#GObject::notify emissions) may be emitted in threads other than the one which created
+	 * the #GDataDownloadStream. It is the client's responsibility to ensure that any notification signal handlers are either multi-thread safe
+	 * or marshal the notification to the thread which owns the #GDataDownloadStream as appropriate.
+	 *
 	 * Since: 0.5.0
 	 **/
 	g_object_class_install_property (gobject_class, PROP_CONTENT_TYPE,
@@ -151,6 +155,10 @@ gdata_download_stream_class_init (GDataDownloadStreamClass *klass)
 	 *
 	 * The length (in bytes) of the file being downloaded.
 	 *
+	 * Note that change notifications for this property (#GObject::notify emissions) may be emitted in threads other than the one which created
+	 * the #GDataDownloadStream. It is the client's responsibility to ensure that any notification signal handlers are either multi-thread safe
+	 * or marshal the notification to the thread which owns the #GDataDownloadStream as appropriate.
+	 *
 	 * Since: 0.5.0
 	 **/
 	g_object_class_install_property (gobject_class, PROP_CONTENT_LENGTH,
@@ -408,19 +416,6 @@ gdata_download_stream_truncate (GSeekable *seekable, goffset offset, GCancellabl
 	return FALSE;
 }
 
-static gboolean
-notify_content_data_cb (GObject *download_stream)
-{
-	g_object_freeze_notify (download_stream);
-	g_object_notify (download_stream, "content-length");
-	g_object_notify (download_stream, "content-type");
-	g_object_thaw_notify (download_stream);
-
-	g_object_unref (download_stream);
-
-	return FALSE;
-}
-
 static void
 got_headers_cb (SoupMessage *message, GDataDownloadStream *self)
 {
@@ -434,8 +429,11 @@ got_headers_cb (SoupMessage *message, GDataDownloadStream *self)
 	self->priv->content_length = soup_message_headers_get_content_length (message->response_headers);
 	g_static_mutex_unlock (&(self->priv->content_mutex));
 
-	/* Emit the notifications for the Content-Length and -Type properties in the main thread */
-	g_idle_add ((GSourceFunc) notify_content_data_cb, g_object_ref (self));
+	/* Emit the notifications for the Content-Length and -Type properties */
+	g_object_freeze_notify (G_OBJECT (self));
+	g_object_notify (G_OBJECT (self), "content-length");
+	g_object_notify (G_OBJECT (self), "content-type");
+	g_object_thaw_notify (G_OBJECT (self));
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]