[glib] Fix thread safety of g_get_language_names()
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Fix thread safety of g_get_language_names()
- Date: Sat, 26 Mar 2016 12:54:10 +0000 (UTC)
commit 41888493f04bfcc42d5287267708edcc49d7b4ea
Author: Benjamin Gilbert <bgilbert backtick net>
Date: Sun Apr 26 00:53:09 2015 -0400
Fix thread safety of g_get_language_names()
https://bugzilla.gnome.org/show_bug.cgi?id=748474
glib/gcharset.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/glib/gcharset.c b/glib/gcharset.c
index 0a4b0da..d47541c 100644
--- a/glib/gcharset.c
+++ b/glib/gcharset.c
@@ -228,17 +228,14 @@ g_get_codeset (void)
#ifndef G_OS_WIN32
-static GHashTable *alias_table = NULL;
-
/* read an alias file for the locales */
static void
-read_aliases (gchar *file)
+read_aliases (gchar *file,
+ GHashTable *alias_table)
{
FILE *fp;
char buf[256];
- if (!alias_table)
- alias_table = g_hash_table_new (g_str_hash, g_str_equal);
fp = fopen (file,"r");
if (!fp)
return;
@@ -289,11 +286,16 @@ static char *
unalias_lang (char *lang)
{
#ifndef G_OS_WIN32
+ static GHashTable *alias_table = NULL;
char *p;
int i;
- if (!alias_table)
- read_aliases ("/usr/share/locale/locale.alias");
+ if (g_once_init_enter (&alias_table))
+ {
+ GHashTable *table = g_hash_table_new (g_str_hash, g_str_equal);
+ read_aliases ("/usr/share/locale/locale.alias", table);
+ g_once_init_leave (&alias_table, table);
+ }
i = 0;
while ((p = g_hash_table_lookup (alias_table, lang)) && (strcmp (p, lang) != 0))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]