[glib/gobject-speedups3: 1/2] param: Add private api for batched lookups




commit b50c9f3aae152591bad3d01d8d6ed96a1b9de7aa
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 20 07:58:59 2022 -0400

    param: Add private api for batched lookups
    
    The pspec pool mutex is showing up on
    profiles for object creation and property
    setting.
    
    Add private api that will let us lookups
    of multiple param specs while holding the
    pool mutex, to reduce the locking overhead.

 gobject/gparam.c | 48 +++++++++++++++++++++++++++++-------------------
 gobject/gparam.h |  8 ++++++++
 2 files changed, 37 insertions(+), 19 deletions(-)
---
diff --git a/gobject/gparam.c b/gobject/gparam.c
index 4311dbbc68..cee48ab65d 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -1098,21 +1098,41 @@ g_param_spec_pool_lookup (GParamSpecPool *pool,
   g_return_val_if_fail (pool != NULL, NULL);
   g_return_val_if_fail (param_name != NULL, NULL);
 
+  g_param_spec_pool_acquire (pool);
+  pspec = g_param_spec_pool_find (pool, param_name, owner_type, walk_ancestors);
+  g_param_spec_pool_release (pool);
+
+  return pspec;
+}
+
+void
+g_param_spec_pool_acquire (GParamSpecPool *pool)
+{
   g_mutex_lock (&pool->mutex);
+}
+
+void
+g_param_spec_pool_release (GParamSpecPool *pool)
+{
+  g_mutex_unlock (&pool->mutex);
+}
+
+GParamSpec *
+g_param_spec_pool_find (GParamSpecPool *pool,
+                        const char     *param_name,
+                        GType           owner_type,
+                        gboolean        walk_ancestors)
+{
+  GParamSpec *pspec;
 
   /* try quick and away, i.e. without prefix */
   pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors);
   if (pspec)
-    {
-      g_mutex_unlock (&pool->mutex);
-      return pspec;
-    }
+    return pspec;
 
   if (pool->type_prefixing)
     {
-      char *delim;
-
-      delim = strchr (param_name, ':');
+      char *delim = strchr (param_name, ':');
 
       /* strip type prefix */
       if (delim && delim[1] == ':')
@@ -1130,25 +1150,15 @@ g_param_spec_pool_lookup (GParamSpecPool *pool,
             {
               /* sanity check, these cases don't make a whole lot of sense */
               if ((!walk_ancestors && type != owner_type) || !g_type_is_a (owner_type, type))
-                {
-                  g_mutex_unlock (&pool->mutex);
+                return NULL;
 
-                  return NULL;
-                }
               owner_type = type;
               param_name += l + 2;
-              pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors);
-              g_mutex_unlock (&pool->mutex);
-
-              return pspec;
+              return param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors);
             }
         }
     }
 
-  /* malformed param_name */
-
-  g_mutex_unlock (&pool->mutex);
-
   return NULL;
 }
 
diff --git a/gobject/gparam.h b/gobject/gparam.h
index fea6e502c8..9bff364d11 100644
--- a/gobject/gparam.h
+++ b/gobject/gparam.h
@@ -443,6 +443,14 @@ GParamSpec**       g_param_spec_pool_list          (GParamSpecPool *pool,
                                                 GType           owner_type,
                                                 guint          *n_pspecs_p);
 
+/* private */
+
+void            g_param_spec_pool_acquire       (GParamSpecPool *pool);
+void            g_param_spec_pool_release       (GParamSpecPool *pool);
+GParamSpec *    g_param_spec_pool_find          (GParamSpecPool *pool,
+                                                 const char     *param_name,
+                                                 GType           owner_type,
+                                                 gboolean        walk_ancestors);
 
 /* contracts:
  *


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