[gnome-color-manager] trivial: Use a mutex to make GcmDevice thread-safe



commit 9d9e5f9a95a67582291f9a8662f7e7b05afa4919
Author: Richard Hughes <richard hughsie com>
Date:   Wed Mar 24 12:27:30 2010 +0000

    trivial: Use a mutex to make GcmDevice thread-safe

 src/gcm-device.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/gcm-device.c b/src/gcm-device.c
index 4f40fd1..cdac153 100644
--- a/src/gcm-device.c
+++ b/src/gcm-device.c
@@ -94,6 +94,8 @@ static guint signals[SIGNAL_LAST] = { 0 };
 
 G_DEFINE_TYPE (GcmDevice, gcm_device, G_TYPE_OBJECT)
 
+#define GCM_DEVICE_CHANGED_SUPRESS_TIMEOUT	10	/* ms */
+
 /**
  * gcm_device_changed_cb:
  **/
@@ -113,12 +115,24 @@ gcm_device_changed_cb (GcmDevice *device)
 static void
 gcm_device_changed (GcmDevice *device)
 {
+	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+
+	/* lock */
+	g_static_mutex_lock (&mutex);
+
 	/* already queued, so ignoring */
 	if (device->priv->changed_id != 0)
-		return;
+		goto out;
 
 	/* adding to queue */
-	device->priv->changed_id = g_idle_add ((GSourceFunc) gcm_device_changed_cb, device);
+	device->priv->changed_id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE,
+						       GCM_DEVICE_CHANGED_SUPRESS_TIMEOUT,
+						       (GSourceFunc) gcm_device_changed_cb,
+						       g_object_ref (device),
+						       (GDestroyNotify) g_object_unref);
+out:
+	/* unlock */
+	g_static_mutex_unlock (&mutex);
 }
 
 /**



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