summaryrefslogtreecommitdiff
path: root/pango/pango-language.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2012-08-27 22:40:53 -0400
committerBehdad Esfahbod <behdad@behdad.org>2012-08-27 22:55:25 -0400
commit39d0a94a735abedbfa6ff2b20ab3da1314c84f89 (patch)
treec39ac6e4dd1be50f76d1606c7ece2702ca3c78a4 /pango/pango-language.c
parentbb8bf13fea27a77c53e7692dce827e2839216fc6 (diff)
downloadpango-39d0a94a735abedbfa6ff2b20ab3da1314c84f89.tar.gz
Make pango-language.c thread-safe
Start marking static-data that is thread safe with the "MT-safe" marker. The following grep can be used to track progress: grep 'static[^(]*;' *c | grep -v MT-safe
Diffstat (limited to 'pango/pango-language.c')
-rw-r--r--pango/pango-language.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/pango/pango-language.c b/pango/pango-language.c
index 9af84892..7fc7078e 100644
--- a/pango/pango-language.c
+++ b/pango/pango-language.c
@@ -252,13 +252,18 @@ _pango_get_lc_ctype (void)
PangoLanguage *
pango_language_get_default (void)
{
- static PangoLanguage *result = NULL;
+ static PangoLanguage *result = NULL; /* MT-safe */
- if (G_UNLIKELY (!result))
+ if (g_once_init_enter (&result))
{
- gchar *lang = _pango_get_lc_ctype ();
- result = pango_language_from_string (lang);
- g_free (lang);
+ gchar *lc_ctype;
+ PangoLanguage *lang;
+
+ lc_ctype = _pango_get_lc_ctype ();
+ lang = pango_language_from_string (lc_ctype);
+ g_free (lc_ctype);
+
+ g_once_init_leave (&result, lang);
}
return result;
@@ -288,7 +293,8 @@ pango_language_get_default (void)
PangoLanguage *
pango_language_from_string (const char *language)
{
- static GHashTable *hash = NULL;
+ G_LOCK_DEFINE_STATIC (lang_from_string);
+ static GHashTable *hash = NULL; /* MT-safe */
PangoLanguagePrivate *priv;
char *result;
int len;
@@ -297,13 +303,15 @@ pango_language_from_string (const char *language)
if (language == NULL)
return NULL;
+ G_LOCK (lang_from_string);
+
if (G_UNLIKELY (!hash))
hash = g_hash_table_new (lang_hash, lang_equal);
else
{
result = g_hash_table_lookup (hash, language);
if (result)
- return (PangoLanguage *)result;
+ goto out;
}
len = strlen (language);
@@ -321,6 +329,9 @@ pango_language_from_string (const char *language)
g_hash_table_insert (hash, result, result);
+out:
+ G_UNLOCK (lang_from_string);
+
return (PangoLanguage *)result;
}
@@ -744,11 +755,14 @@ parse_default_languages (void)
static PangoLanguage *
_pango_script_get_default_language (PangoScript script)
{
- static gboolean initialized = FALSE;
- static PangoLanguage * const * languages = NULL;
- static GHashTable *hash = NULL;
+ G_LOCK_DEFINE_STATIC (languages);
+ static gboolean initialized = FALSE; /* MT-safe */
+ static PangoLanguage * const * languages = NULL; /* MT-safe */
+ static GHashTable *hash = NULL; /* MT-safe */
PangoLanguage *result, * const * p;
+ G_LOCK (languages);
+
if (G_UNLIKELY (!initialized))
{
languages = parse_default_languages ();
@@ -760,10 +774,13 @@ _pango_script_get_default_language (PangoScript script)
}
if (!languages)
- return NULL;
+ {
+ result = NULL;
+ goto out;
+ }
if (g_hash_table_lookup_extended (hash, GINT_TO_POINTER (script), NULL, (gpointer *) (gpointer) &result))
- return result;
+ goto out;
for (p = languages; *p; p++)
if (pango_language_includes_script (*p, script))
@@ -772,6 +789,9 @@ _pango_script_get_default_language (PangoScript script)
g_hash_table_insert (hash, GINT_TO_POINTER (script), result);
+out:
+ G_UNLOCK (languages);
+
return result;
}