[gvfs/gdbus] gdbus: Add locking for local lists



commit 501a80b51ffbd0d21e28a26e3680391c303f7c37
Author: Tomas Bzatek <tbzatek redhat com>
Date:   Wed May 18 14:28:07 2011 +0200

    gdbus: Add locking for local lists

 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 2bd2ae7..c26a37f 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);
@@ -900,7 +918,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);
@@ -957,6 +977,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);
@@ -972,6 +993,7 @@ handle_mount_op_reply (GVfsRemoteVolumeMonitor *object,
           break;
         }
     }
+  G_UNLOCK (outstanding_mount_op_objects_lock);
 
   if (mount_operation == NULL)
     {
@@ -1087,7 +1109,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);
@@ -1189,7 +1213,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);
@@ -1298,7 +1324,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);
@@ -1414,7 +1442,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);
@@ -1512,7 +1542,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);
@@ -1572,6 +1604,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);
@@ -1589,6 +1622,7 @@ handle_cancel_operation (GVfsRemoteVolumeMonitor *object,
           break;
         }
     }
+  G_UNLOCK (outstanding_ops_lock);
 
   if (!was_cancelled)
     g_warning ("didn't find op to cancel");



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