From 81122277cc4aa8ec71dc679297aa929512a4c159 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Mon, 4 Jun 2012 17:31:10 +0200 Subject: gdbus: Use a static lock for metadata proxy instead of GPrivate Using GPrivate turned to be problematic wrt thread safety, better to use the standard way of locks. --- client/gdaemonfile.c | 52 +++------------------------------------------------- 1 file changed, 3 insertions(+), 49 deletions(-) (limited to 'client/gdaemonfile.c') diff --git a/client/gdaemonfile.c b/client/gdaemonfile.c index 5c4f76ba..5ab98d66 100644 --- a/client/gdaemonfile.c +++ b/client/gdaemonfile.c @@ -29,6 +29,7 @@ #include #include "gdaemonfile.h" +#include "gdaemonvfs.h" #include "gvfsdaemondbus.h" #include "gdaemonmount.h" #include @@ -55,8 +56,6 @@ G_DEFINE_TYPE_WITH_CODE (GDaemonFile, g_daemon_file, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_FILE, g_daemon_file_file_iface_init)) -static GPrivate metadata_proxy = G_PRIVATE_INIT (g_object_unref); - static void g_daemon_file_finalize (GObject *object) { @@ -2209,52 +2208,6 @@ g_daemon_file_query_writable_namespaces (GFile *file, return list; } -static void -metadata_daemon_vanished (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - guint *watcher_id = user_data; - - g_private_replace (&metadata_proxy, NULL); - if (*watcher_id > 0) - g_bus_unwatch_name (*watcher_id); -} - -static GVfsMetadata * -get_metadata_proxy (GCancellable *cancellable, GError **error) -{ - GVfsMetadata *proxy; - guint *watcher_id; - - proxy = g_private_get (&metadata_proxy); - if (proxy == NULL) - { - proxy = gvfs_metadata_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_NONE, - G_VFS_DBUS_METADATA_NAME, - G_VFS_DBUS_METADATA_PATH, - cancellable, - error); - g_private_replace (&metadata_proxy, proxy); - - if (proxy == NULL) - return NULL; - - /* a place in memory to store the returned ID in */ - watcher_id = g_malloc0 (sizeof (guint)); - *watcher_id = g_bus_watch_name_on_connection (g_dbus_proxy_get_connection (G_DBUS_PROXY (proxy)), - G_VFS_DBUS_METADATA_NAME, - G_BUS_NAME_WATCHER_FLAGS_AUTO_START, - NULL, - metadata_daemon_vanished, - watcher_id, - g_free); - } - - return proxy; -} - static gboolean set_metadata_attribute (GFile *file, const char *attribute, @@ -2279,7 +2232,7 @@ set_metadata_attribute (GFile *file, g_free (treename); res = FALSE; - proxy = get_metadata_proxy (cancellable, error); + proxy = _g_daemon_vfs_get_metadata_proxy (cancellable, error); if (proxy) { @@ -2313,6 +2266,7 @@ set_metadata_attribute (GFile *file, res = FALSE; g_variant_builder_unref (builder); + g_object_unref (proxy); } meta_tree_unref (tree); -- cgit v1.2.1