[dconf] Change locking in the engine



commit da7229b0b2c3a4aec392a042fd231bea7aaecfc0
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu May 5 15:38:21 2011 +0200

    Change locking in the engine
    
    Switch from code locking to data locking and hold the data lock quite a
    lot more often.
    
    We could try to be more clever about finding ways to hold locks less
    often but I think it's not really worth it.
    
    Closes #648949

 engine/dconf-engine.c |   35 ++++++++++++++++++++++++++++-------
 1 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c
index 86cc9cc..9181fc2 100644
--- a/engine/dconf-engine.c
+++ b/engine/dconf-engine.c
@@ -122,6 +122,7 @@ dconf_engine_get_session_dir (void)
 
 struct _DConfEngine
 {
+  GStaticMutex lock;
   guint64     state;
 
   guint8     *shm;
@@ -238,22 +239,23 @@ dconf_engine_refresh_system (DConfEngine *engine)
 static void
 dconf_engine_refresh (DConfEngine *engine)
 {
-  static GStaticMutex lock;
-
-  g_static_mutex_lock (&lock);
-
   dconf_engine_refresh_system (engine);
   dconf_engine_refresh_user (engine);
-
-  g_static_mutex_unlock (&lock);
 }
 
 guint64
 dconf_engine_get_state (DConfEngine *engine)
 {
+  guint64 state;
+
+  g_static_mutex_lock (&engine->lock);
+
   dconf_engine_refresh (engine);
+  state = engine->state;
+
+  g_static_mutex_unlock (&engine->lock);
 
-  return engine->state;
+  return state;
 }
 
 static gboolean
@@ -324,6 +326,7 @@ dconf_engine_new (const gchar *profile)
   gint i;
 
   engine = g_slice_new (DConfEngine);
+  g_static_mutex_init (&engine->lock);
   engine->shm = NULL;
 
   if (profile == NULL)
@@ -394,6 +397,8 @@ dconf_engine_free (DConfEngine *engine)
       munmap (engine->shm, 1);
     }
 
+  g_static_mutex_free (&engine->lock);
+
   g_free (engine->object_paths);
   g_free (engine->bus_types);
   g_free (engine->names);
@@ -409,6 +414,8 @@ dconf_engine_read (DConfEngine  *engine,
   GVariant *value = NULL;
   gint i;
 
+  g_static_mutex_lock (&engine->lock);
+
   dconf_engine_refresh (engine);
 
   if (engine->gvdbs[0])
@@ -417,6 +424,8 @@ dconf_engine_read (DConfEngine  *engine,
   for (i = 1; i < engine->n_dbs && value == NULL; i++)
     value = gvdb_table_get_value (engine->gvdbs[i], key);
 
+  g_static_mutex_unlock (&engine->lock);
+
   return value;
 }
 
@@ -427,11 +436,15 @@ dconf_engine_read_default (DConfEngine  *engine,
   GVariant *value = NULL;
   gint i;
 
+  g_static_mutex_lock (&engine->lock);
+
   dconf_engine_refresh (engine);
 
   for (i = 1; i < engine->n_dbs && value == NULL; i++)
     value = gvdb_table_get_value (engine->gvdbs[i], key);
 
+  g_static_mutex_unlock (&engine->lock);
+
   return value;
 }
 
@@ -441,11 +454,15 @@ dconf_engine_read_no_default (DConfEngine  *engine,
 {
   GVariant *value = NULL;
 
+  g_static_mutex_lock (&engine->lock);
+
   dconf_engine_refresh (engine);
 
   if (engine->gvdbs[0])
     value = gvdb_table_get_value (engine->gvdbs[0], key);
 
+  g_static_mutex_unlock (&engine->lock);
+
   return value;
 }
 
@@ -602,6 +619,8 @@ dconf_engine_list (DConfEngine    *engine,
   /* not yet supported */
   g_assert (resets == NULL);
 
+  g_static_mutex_lock (&engine->lock);
+
   dconf_engine_refresh (engine);
 
   if (engine->gvdbs[0])
@@ -615,6 +634,8 @@ dconf_engine_list (DConfEngine    *engine,
   if (length)
     *length = g_strv_length (list);
 
+  g_static_mutex_unlock (&engine->lock);
+
   return list;
 }
 



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