diff options
author | Tomas Bzatek <tbzatek@redhat.com> | 2011-05-18 14:28:07 +0200 |
---|---|---|
committer | Tomas Bzatek <tbzatek@redhat.com> | 2012-05-21 15:50:27 +0200 |
commit | fca099e8bf364c138c681a65418dc483096c6464 (patch) | |
tree | b947bedd450d1847427930d1cfe1efa5e1e0bc21 | |
parent | 5669ac420797d49d616181f07ec6cdf81dc8f3a5 (diff) | |
download | gvfs-fca099e8bf364c138c681a65418dc483096c6464.tar.gz |
gdbus: Add locking for local lists
-rw-r--r-- | monitor/proxy/gvfsproxyvolumemonitordaemon.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/monitor/proxy/gvfsproxyvolumemonitordaemon.c b/monitor/proxy/gvfsproxyvolumemonitordaemon.c index 33eeae5b..564f8a78 100644 --- a/monitor/proxy/gvfsproxyvolumemonitordaemon.c +++ b/monitor/proxy/gvfsproxyvolumemonitordaemon.c @@ -44,6 +44,10 @@ static GHashTable *unique_names_being_watched = NULL; static GVfsRemoteVolumeMonitor *monitor_daemon = NULL; +G_LOCK_DEFINE_STATIC (outstanding_ops_lock); +G_LOCK_DEFINE_STATIC (outstanding_mount_op_objects_lock); +G_LOCK_DEFINE_STATIC (unique_names_being_watched_lock); + #define DEBUG_ENABLED #ifdef DEBUG_ENABLED @@ -338,7 +342,9 @@ static void mount_op_destroyed_cb (gpointer user_data, GObject *where_the_mount_op_was) { + G_LOCK (outstanding_mount_op_objects_lock); outstanding_mount_op_objects = g_list_remove (outstanding_mount_op_objects, where_the_mount_op_was); + G_UNLOCK (outstanding_mount_op_objects_lock); } static GMountOperation * @@ -356,7 +362,10 @@ wrap_mount_op (const gchar *mount_op_id, g_object_set_data_full (G_OBJECT (op), "mount_op_id", g_strdup (mount_op_id), g_free); g_object_set_data_full (G_OBJECT (op), "mount_op_owner", g_strdup (mount_op_owner), g_free); + G_LOCK (outstanding_mount_op_objects_lock); outstanding_mount_op_objects = g_list_prepend (outstanding_mount_op_objects, op); + G_UNLOCK (outstanding_mount_op_objects_lock); + g_object_weak_ref (G_OBJECT (op), mount_op_destroyed_cb, NULL); @@ -371,7 +380,9 @@ static void cancellable_destroyed_cb (gpointer user_data, GObject *where_the_cancellable_was) { + G_LOCK (outstanding_ops_lock); outstanding_ops = g_list_remove (outstanding_ops, where_the_cancellable_was); + G_UNLOCK (outstanding_ops_lock); } static void @@ -385,6 +396,7 @@ on_name_owner_vanished (GDBusConnection *connection, print_debug ("Name owner '%s' vanished", name); /* if @name has outstanding mount operation objects; abort them */ + G_LOCK (outstanding_mount_op_objects_lock); for (l = outstanding_mount_op_objects; l != NULL; l = l->next) { GMountOperation *op = G_MOUNT_OPERATION (l->data); @@ -398,8 +410,10 @@ on_name_owner_vanished (GDBusConnection *connection, g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); } } + G_UNLOCK (outstanding_mount_op_objects_lock); /* see if @name has outstanding ops; if so, cancel them */ + G_LOCK (outstanding_ops_lock); for (l = outstanding_ops; l != NULL; l = l->next) { GCancellable *cancellable = G_CANCELLABLE (l->data); @@ -414,8 +428,10 @@ on_name_owner_vanished (GDBusConnection *connection, g_cancellable_cancel (cancellable); } } + G_UNLOCK (outstanding_ops_lock); /* unwatch the name */ + G_LOCK (unique_names_being_watched_lock); name_watcher_id = (gulong) g_hash_table_lookup (unique_names_being_watched, name); if (name_watcher_id == 0) { @@ -427,6 +443,7 @@ on_name_owner_vanished (GDBusConnection *connection, } g_hash_table_remove (unique_names_being_watched, name); + G_UNLOCK (unique_names_being_watched_lock); } static void @@ -437,6 +454,7 @@ ensure_name_owner_changed_for_unique_name (GDBusMethodInvocation *invocation) unique_name = g_dbus_method_invocation_get_sender (invocation); + G_LOCK (unique_names_being_watched_lock); if (g_hash_table_lookup (unique_names_being_watched, unique_name) != NULL) goto out; @@ -450,7 +468,7 @@ ensure_name_owner_changed_for_unique_name (GDBusMethodInvocation *invocation) g_hash_table_insert (unique_names_being_watched, g_strdup (unique_name), (gpointer) (name_watcher_id + 1)); out: - ; + G_UNLOCK (unique_names_being_watched_lock); } static void monitor_try_create (void); @@ -952,7 +970,9 @@ handle_mount_unmount (GVfsRemoteVolumeMonitor *object, g_object_set_data_full (G_OBJECT (mount), "cancellable", cancellable, g_object_unref); g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free); g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free); + G_LOCK (outstanding_ops_lock); outstanding_ops = g_list_prepend (outstanding_ops, cancellable); + G_UNLOCK (outstanding_ops_lock); g_object_weak_ref (G_OBJECT (cancellable), cancellable_destroyed_cb, NULL); @@ -1009,6 +1029,7 @@ handle_mount_op_reply (GVfsRemoteVolumeMonitor *object, /* Find the op */ mount_operation = NULL; + G_LOCK (outstanding_mount_op_objects_lock); for (l = outstanding_mount_op_objects; l != NULL; l = l->next) { GMountOperation *op = G_MOUNT_OPERATION (l->data); @@ -1024,6 +1045,7 @@ handle_mount_op_reply (GVfsRemoteVolumeMonitor *object, break; } } + G_UNLOCK (outstanding_mount_op_objects_lock); if (mount_operation == NULL) { @@ -1139,7 +1161,9 @@ handle_volume_mount (GVfsRemoteVolumeMonitor *object, g_object_set_data_full (G_OBJECT (volume), "cancellable", cancellable, g_object_unref); g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free); g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free); + G_LOCK (outstanding_ops_lock); outstanding_ops = g_list_prepend (outstanding_ops, cancellable); + G_UNLOCK (outstanding_ops_lock); g_object_weak_ref (G_OBJECT (cancellable), cancellable_destroyed_cb, NULL); @@ -1241,7 +1265,9 @@ handle_drive_eject (GVfsRemoteVolumeMonitor *object, g_object_set_data_full (G_OBJECT (drive), "cancellable", cancellable, g_object_unref); g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free); g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free); + G_LOCK (outstanding_ops_lock); outstanding_ops = g_list_prepend (outstanding_ops, cancellable); + G_UNLOCK (outstanding_ops_lock); g_object_weak_ref (G_OBJECT (cancellable), cancellable_destroyed_cb, NULL); @@ -1350,7 +1376,9 @@ handle_drive_stop (GVfsRemoteVolumeMonitor *object, g_object_set_data_full (G_OBJECT (drive), "cancellable", cancellable, g_object_unref); g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free); g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free); + G_LOCK (outstanding_ops_lock); outstanding_ops = g_list_prepend (outstanding_ops, cancellable); + G_UNLOCK (outstanding_ops_lock); g_object_weak_ref (G_OBJECT (cancellable), cancellable_destroyed_cb, NULL); @@ -1466,7 +1494,9 @@ handle_drive_start (GVfsRemoteVolumeMonitor *object, g_object_set_data_full (G_OBJECT (drive), "cancellable", cancellable, g_object_unref); g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free); g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free); + G_LOCK (outstanding_ops_lock); outstanding_ops = g_list_prepend (outstanding_ops, cancellable); + G_UNLOCK (outstanding_ops_lock); g_object_weak_ref (G_OBJECT (cancellable), cancellable_destroyed_cb, NULL); @@ -1564,7 +1594,9 @@ handle_drive_poll_for_media (GVfsRemoteVolumeMonitor *object, g_object_set_data_full (G_OBJECT (drive), "cancellable", cancellable, g_object_unref); g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free); g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free); + G_LOCK (outstanding_ops_lock); outstanding_ops = g_list_prepend (outstanding_ops, cancellable); + G_UNLOCK (outstanding_ops_lock); g_object_weak_ref (G_OBJECT (cancellable), cancellable_destroyed_cb, NULL); @@ -1624,6 +1656,7 @@ handle_cancel_operation (GVfsRemoteVolumeMonitor *object, print_debug ("in handle_cancel_operation"); /* Find GCancellable to cancel */ + G_LOCK (outstanding_ops_lock); for (l = outstanding_ops; l != NULL; l = l->next) { GCancellable *cancellable = G_CANCELLABLE (l->data); @@ -1641,6 +1674,7 @@ handle_cancel_operation (GVfsRemoteVolumeMonitor *object, break; } } + G_UNLOCK (outstanding_ops_lock); if (!was_cancelled) g_warning ("didn't find op to cancel"); |