[glib/gobject-speedups3: 34/35] param: Add private api for batched lookups




commit d9415af2db3a33ba58091fce3273f93c25cba41a
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 85a91a5724..a3924ebcaf 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -1125,21 +1125,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] == ':')
@@ -1157,25 +1177,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 5bb45ad3e2..29a5b0123a 100644
--- a/gobject/gparam.h
+++ b/gobject/gparam.h
@@ -452,6 +452,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]