[pango] Make modules.c thread-safe
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] Make modules.c thread-safe
- Date: Sun, 16 Sep 2012 15:06:19 +0000 (UTC)
commit 25779da81f66bfb7118395757cf1a031af09b068
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Sep 14 22:12:30 2012 -0400
Make modules.c thread-safe
The maps list is protected with a mutex.
registered_engines, dlloaded_engines and dlloaded_modules are
read-only after init_modules, which is protected with g_once_init.
Finally, engine creation is protected with another mutex.
pango/modules.c | 34 +++++++++++++++++++++++-----------
1 files changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/pango/modules.c b/pango/modules.c
index 1fbd58d..644cc9c 100644
--- a/pango/modules.c
+++ b/pango/modules.c
@@ -88,7 +88,9 @@ struct _PangoModuleClass
GTypeModuleClass parent_class;
};
+G_LOCK_DEFINE_STATIC (maps);
static GList *maps = NULL;
+/* the following are readonly after init_modules */
static GSList *registered_engines = NULL;
static GSList *dlloaded_engines = NULL;
static GHashTable *dlloaded_modules;
@@ -131,10 +133,13 @@ pango_find_map (PangoLanguage *language,
guint engine_type_id,
guint render_type_id)
{
- GList *tmp_list = maps;
+ GList *tmp_list;
PangoMapInfo *map_info = NULL;
gboolean found_earlier = FALSE;
+ G_LOCK (maps);
+
+ tmp_list = maps;
while (tmp_list)
{
map_info = tmp_list->data;
@@ -173,6 +178,8 @@ pango_find_map (PangoLanguage *language,
g_list_free_1(tmp_list);
}
+ G_UNLOCK (maps);
+
return map_info->map;
}
@@ -278,10 +285,13 @@ pango_module_class_init (PangoModuleClass *class)
gobject_class->finalize = pango_module_finalize;
}
+G_LOCK_DEFINE_STATIC (engine);
static PangoEngine *
pango_engine_pair_get_engine (PangoEnginePair *pair)
{
+ G_LOCK (engine);
+
if (!pair->engine)
{
if (g_type_module_use (G_TYPE_MODULE (pair->module)))
@@ -303,6 +313,8 @@ pango_engine_pair_get_engine (PangoEnginePair *pair)
}
}
+ G_UNLOCK (engine);
+
return pair->engine;
}
@@ -573,20 +585,20 @@ read_modules (void)
static void
init_modules (void)
{
- static gboolean init = FALSE;
+ static gsize init = 0;
int i;
- if (init)
- return;
- else
- init = TRUE;
+ if (g_once_init_enter (&init))
+ {
+ /* Make sure that the type system is initialized */
+ g_type_init ();
- /* Make sure that the type system is initialized */
- g_type_init ();
+ for (i = 0; _pango_included_lang_modules[i].list; i++)
+ pango_module_register (&_pango_included_lang_modules[i]);
+ read_modules ();
- for (i = 0; _pango_included_lang_modules[i].list; i++)
- pango_module_register (&_pango_included_lang_modules[i]);
- read_modules ();
+ g_once_init_leave (&init, 1);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]