[gnome-color-manager] Only emit ::added signals from the main thread, not the coldplug threads
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Only emit ::added signals from the main thread, not the coldplug threads
- Date: Mon, 14 Jun 2010 08:57:06 +0000 (UTC)
commit f9da239539e7b5bfe0323b813e65e971264db802
Author: Richard Hughes <richard hughsie com>
Date: Mon Jun 14 09:45:22 2010 +0100
Only emit ::added signals from the main thread, not the coldplug threads
src/gcm-client.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 44 insertions(+), 6 deletions(-)
---
diff --git a/src/gcm-client.c b/src/gcm-client.c
index e215d26..f1e051c 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -82,6 +82,7 @@ struct _GcmClientPrivate
gboolean init_cups;
gboolean init_sane;
guint refresh_id;
+ guint emit_added_id;
};
enum {
@@ -1177,6 +1178,44 @@ out:
return ret;
}
+typedef struct {
+ GcmClient *client;
+ GcmDevice *device;
+} GcmClientEmitHelper;
+
+/**
+ * gcm_client_emit_added_idle_cb:
+ **/
+static gboolean
+gcm_client_emit_added_idle_cb (GcmClientEmitHelper *helper)
+{
+ /* emit a signal */
+ egg_debug ("emit added: %s", gcm_device_get_id (helper->device));
+ g_signal_emit (helper->client, signals[SIGNAL_ADDED], 0, helper->device);
+ helper->client->priv->emit_added_id = 0;
+
+ g_object_unref (helper->client);
+ g_object_unref (helper->device);
+ g_free (helper);
+ return FALSE;
+}
+
+/**
+ * gcm_client_emit_added_idle:
+ **/
+static void
+gcm_client_emit_added_idle (GcmClient *client, GcmDevice *device)
+{
+ GcmClientEmitHelper *helper;
+ helper = g_new0 (GcmClientEmitHelper, 1);
+ helper->client = g_object_ref (client);
+ helper->device = g_object_ref (device);
+ client->priv->emit_added_id = g_idle_add ((GSourceFunc) gcm_client_emit_added_idle_cb, helper);
+#if GLIB_CHECK_VERSION(2,25,8)
+ g_source_set_name_by_id (client->priv->emit_added_id, "[GcmClient] emit added for device");
+#endif
+}
+
/**
* gcm_client_add_device:
**/
@@ -1214,14 +1253,11 @@ gcm_client_add_device (GcmClient *client, GcmDevice *device, GError **error)
/* add to the array */
g_ptr_array_add (client->priv->array, g_object_ref (device));
-
- /* emit a signal */
- egg_debug ("emit added: %s", device_id);
- g_signal_emit (client, signals[SIGNAL_ADDED], 0, device);
-
- /* connect to the changed signal */
g_signal_connect (device, "changed", G_CALLBACK (gcm_client_device_changed_cb), client);
+ /* emit a signal from the main thread, not this one */
+ gcm_client_emit_added_idle (client, device);
+
/* all okay */
ret = TRUE;
out:
@@ -1475,6 +1511,8 @@ gcm_client_finalize (GObject *object)
/* disconnect anything that's about to fire */
if (priv->refresh_id != 0)
g_source_remove (priv->refresh_id);
+ if (priv->emit_added_id != 0)
+ g_source_remove (priv->emit_added_id);
/* do not respond to changed events */
for (i=0; i<priv->array->len; i++) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]