glib r6630 - trunk/gio



Author: alexl
Date: Wed Mar  5 11:50:27 2008
New Revision: 6630
URL: http://svn.gnome.org/viewvc/glib?rev=6630&view=rev

Log:
2008-03-05  Alexander Larsson  <alexl redhat com>

        * gfilemonitor.c:
	Make cancellation threadsafe (i.e.
	guarantee its only done once, and always
	done)
	
        * glocaldirectorymonitor.c:
	Make sure we the monitor lives while the
	mounts_changed callback is being called (#520484)



Modified:
   trunk/gio/ChangeLog
   trunk/gio/gfilemonitor.c
   trunk/gio/glocaldirectorymonitor.c

Modified: trunk/gio/gfilemonitor.c
==============================================================================
--- trunk/gio/gfilemonitor.c	(original)
+++ trunk/gio/gfilemonitor.c	Wed Mar  5 11:50:27 2008
@@ -45,6 +45,8 @@
  * are monitoring, connect to the #GFileMonitor::changed signal.
  **/
 
+G_LOCK_DEFINE_STATIC(cancelled);
+
 enum {
   CHANGED,
   LAST_SIGNAL
@@ -117,7 +119,9 @@
       break;
 
     case PROP_CANCELLED:
+      G_LOCK (cancelled);
       g_value_set_boolean (value, priv->cancelled);
+      G_UNLOCK (cancelled);
       break;
 
     default:
@@ -165,8 +169,7 @@
   monitor = G_FILE_MONITOR (object);
 
   /* Make sure we cancel on last unref */
-  if (!monitor->priv->cancelled)
-    g_file_monitor_cancel (monitor);
+  g_file_monitor_cancel (monitor);
   
   if (G_OBJECT_CLASS (g_file_monitor_parent_class)->dispose)
     (*G_OBJECT_CLASS (g_file_monitor_parent_class)->dispose) (object);
@@ -247,8 +250,13 @@
 g_file_monitor_is_cancelled (GFileMonitor *monitor)
 {
   g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
+  gboolean res;
 
-  return monitor->priv->cancelled;
+  G_LOCK (cancelled);
+  res = monitor->priv->cancelled;
+  G_UNLOCK (cancelled);
+  
+  return res;
 }
 
 /**
@@ -266,10 +274,16 @@
   
   g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
   
+  G_LOCK (cancelled);
   if (monitor->priv->cancelled)
-    return TRUE;
+    {
+      G_UNLOCK (cancelled);
+      return TRUE;
+    }
   
   monitor->priv->cancelled = TRUE;
+  G_UNLOCK (cancelled);
+  
   g_object_notify (G_OBJECT (monitor), "cancelled");
 
   klass = G_FILE_MONITOR_GET_CLASS (monitor);

Modified: trunk/gio/glocaldirectorymonitor.c
==============================================================================
--- trunk/gio/glocaldirectorymonitor.c	(original)
+++ trunk/gio/glocaldirectorymonitor.c	Wed Mar  5 11:50:27 2008
@@ -128,8 +128,8 @@
         g_unix_mount_free (mount);
 
       local_monitor->mount_monitor = g_unix_mount_monitor_new ();
-      g_signal_connect (local_monitor->mount_monitor, "mounts_changed",
-        G_CALLBACK (mounts_changed), local_monitor);
+      g_signal_connect_object (local_monitor->mount_monitor, "mounts_changed",
+			       G_CALLBACK (mounts_changed), local_monitor, 0);
 #endif
     }
 



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