summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2012-09-14 22:12:30 -0400
committerMatthias Clasen <mclasen@redhat.com>2012-09-14 22:12:30 -0400
commit25779da81f66bfb7118395757cf1a031af09b068 (patch)
treed62665e113b6d64ce1485f0b15ab9367e97258ce /pango
parent164c6eb4dc819eb0833d6851f9e16d4994e84e97 (diff)
downloadpango-25779da81f66bfb7118395757cf1a031af09b068.tar.gz
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.
Diffstat (limited to 'pango')
-rw-r--r--pango/modules.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/pango/modules.c b/pango/modules.c
index 1fbd58de..644cc9cb 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