[gvfs/gdbus: 26/30] gdbus: Use shared metadata proxy for every thread



commit 8f8628960d724c1d01ebd53a9f3e6060fed4b404
Author: Tomas Bzatek <tbzatek redhat com>
Date:   Fri May 18 17:23:01 2012 +0200

    gdbus: Use shared metadata proxy for every thread
    
    This helps to avoid constant metadata proxy creation for every call.
    Instead, create it on first use and store it as thread-local data.
    It gets unreff'ed on thread end automatically.

 client/gdaemonfile.c |   30 +++++++++++++++++++++++-------
 client/gdaemonvfs.c  |   48 ++++++++++++++++++++++++------------------------
 2 files changed, 47 insertions(+), 31 deletions(-)
---
diff --git a/client/gdaemonfile.c b/client/gdaemonfile.c
index 4f400fa..514cf67 100644
--- a/client/gdaemonfile.c
+++ b/client/gdaemonfile.c
@@ -55,6 +55,8 @@ 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)
 {
@@ -2207,6 +2209,26 @@ g_daemon_file_query_writable_namespaces (GFile                      *file,
   return list;
 }
 
+static GVfsMetadata *
+get_metadata_proxy (GCancellable *cancellable, GError **error)
+{
+  GVfsMetadata *proxy;
+
+  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);
+    }
+
+  return proxy;
+}
+
 static gboolean
 set_metadata_attribute (GFile *file,
 			const char *attribute,
@@ -2231,12 +2253,7 @@ set_metadata_attribute (GFile *file,
   g_free (treename);
   
   res = FALSE;
-  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);
+  proxy = get_metadata_proxy (cancellable, error);
 
   if (proxy)
     {
@@ -2270,7 +2287,6 @@ set_metadata_attribute (GFile *file,
         res = FALSE;
 
       g_variant_builder_unref (builder);
-      g_object_unref (proxy);
     }
 
   meta_tree_unref (tree);
diff --git a/client/gdaemonvfs.c b/client/gdaemonvfs.c
index df2a33d..cb36771 100644
--- a/client/gdaemonvfs.c
+++ b/client/gdaemonvfs.c
@@ -77,6 +77,7 @@ struct _GDaemonVfsClass
 G_DEFINE_DYNAMIC_TYPE (GDaemonVfs, g_daemon_vfs, G_TYPE_VFS)
 
 static GDaemonVfs *the_vfs = NULL;
+static GPrivate metadata_proxy = G_PRIVATE_INIT (g_object_unref);
 
 G_LOCK_DEFINE_STATIC(mount_cache);
 
@@ -1281,6 +1282,26 @@ _g_daemon_vfs_append_metadata_for_set (GVariantBuilder *builder,
   return res;
 }
 
+static GVfsMetadata *
+get_metadata_proxy (GError **error)
+{
+  GVfsMetadata *proxy;
+
+  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,
+                                                    NULL,
+                                                    error);
+      g_private_replace (&metadata_proxy, proxy);
+    }
+
+  return proxy;
+}
+
 static gboolean
 g_daemon_vfs_local_file_set_attributes (GVfs       *vfs,
 					const char *filename,
@@ -1333,13 +1354,7 @@ g_daemon_vfs_local_file_set_attributes (GVfs       *vfs,
 						FALSE,
 						&tree_path);
 	  
-	  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,
-	                                                NULL,
-	                                                error);
-
+	  proxy = get_metadata_proxy (error);
 	  if (proxy == NULL)
 	    {
 	      res = FALSE;
@@ -1397,7 +1412,6 @@ g_daemon_vfs_local_file_set_attributes (GVfs       *vfs,
                 }
 
 	      g_variant_builder_unref (builder);
-	      g_object_unref (proxy);
 	      
               meta_lookup_cache_free (cache);
               meta_tree_unref (tree);
@@ -1429,13 +1443,7 @@ g_daemon_vfs_local_file_removed (GVfs       *vfs,
 					&tree_path);
   if (tree)
     {
-      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,
-                                                    NULL,
-                                                    NULL);
-
+      proxy = get_metadata_proxy (NULL);
       if (proxy)
         {
           metatreefile = meta_tree_get_filename (tree);
@@ -1444,7 +1452,6 @@ g_daemon_vfs_local_file_removed (GVfs       *vfs,
                                           tree_path,
                                           NULL,
                                           NULL);
-          g_object_unref (proxy);
         }
       
       meta_tree_unref (tree);
@@ -1478,13 +1485,7 @@ g_daemon_vfs_local_file_moved (GVfs       *vfs,
 					 &tree_path2);
   if (tree1 && tree2 && tree1 == tree2)
     {
-      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,
-                                                    NULL,
-                                                    NULL);
-
+      proxy = get_metadata_proxy (NULL);
       if (proxy)
         {
           metatreefile = meta_tree_get_filename (tree1);
@@ -1494,7 +1495,6 @@ g_daemon_vfs_local_file_moved (GVfs       *vfs,
                                         tree_path2,
                                         NULL,
                                         NULL);
-          g_object_unref (proxy);
         }
     }
 



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