Make cancellation threadsafe (i.e. guarantee its only done once, and

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)


svn path=/trunk/; revision=6630
This commit is contained in:
Alexander Larsson 2008-03-05 11:50:27 +00:00 committed by Alexander Larsson
parent ad649b0bd1
commit 602295158f
3 changed files with 31 additions and 6 deletions

View File

@ -1,3 +1,14 @@
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)
2008-03-04 Wouter Bolsterlee <wbolster@svn.gnome.org> 2008-03-04 Wouter Bolsterlee <wbolster@svn.gnome.org>
* gbufferedinputstream.c: Fix typo in parameter * gbufferedinputstream.c: Fix typo in parameter

View File

@ -45,6 +45,8 @@
* are monitoring, connect to the #GFileMonitor::changed signal. * are monitoring, connect to the #GFileMonitor::changed signal.
**/ **/
G_LOCK_DEFINE_STATIC(cancelled);
enum { enum {
CHANGED, CHANGED,
LAST_SIGNAL LAST_SIGNAL
@ -117,7 +119,9 @@ g_file_monitor_get_property (GObject *object,
break; break;
case PROP_CANCELLED: case PROP_CANCELLED:
G_LOCK (cancelled);
g_value_set_boolean (value, priv->cancelled); g_value_set_boolean (value, priv->cancelled);
G_UNLOCK (cancelled);
break; break;
default: default:
@ -165,7 +169,6 @@ g_file_monitor_dispose (GObject *object)
monitor = G_FILE_MONITOR (object); monitor = G_FILE_MONITOR (object);
/* Make sure we cancel on last unref */ /* 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) if (G_OBJECT_CLASS (g_file_monitor_parent_class)->dispose)
@ -247,8 +250,13 @@ gboolean
g_file_monitor_is_cancelled (GFileMonitor *monitor) g_file_monitor_is_cancelled (GFileMonitor *monitor)
{ {
g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE); 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_file_monitor_cancel (GFileMonitor* monitor)
g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE); g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
G_LOCK (cancelled);
if (monitor->priv->cancelled) if (monitor->priv->cancelled)
{
G_UNLOCK (cancelled);
return TRUE; return TRUE;
}
monitor->priv->cancelled = TRUE; monitor->priv->cancelled = TRUE;
G_UNLOCK (cancelled);
g_object_notify (G_OBJECT (monitor), "cancelled"); g_object_notify (G_OBJECT (monitor), "cancelled");
klass = G_FILE_MONITOR_GET_CLASS (monitor); klass = G_FILE_MONITOR_GET_CLASS (monitor);

View File

@ -128,8 +128,8 @@ g_local_directory_monitor_constructor (GType type,
g_unix_mount_free (mount); g_unix_mount_free (mount);
local_monitor->mount_monitor = g_unix_mount_monitor_new (); local_monitor->mount_monitor = g_unix_mount_monitor_new ();
g_signal_connect (local_monitor->mount_monitor, "mounts_changed", g_signal_connect_object (local_monitor->mount_monitor, "mounts_changed",
G_CALLBACK (mounts_changed), local_monitor); G_CALLBACK (mounts_changed), local_monitor, 0);
#endif #endif
} }