Clean up l10n threading stuff
authorRyan Lortie <desrt@desrt.ca>
Fri, 9 Sep 2011 23:48:14 +0000 (19:48 -0400)
committerRyan Lortie <desrt@desrt.ca>
Fri, 9 Sep 2011 23:50:55 +0000 (19:50 -0400)
Remove the explicit thread initialisation functions for g_get_charset(),
g_get_filename_charsets() and g_get_language_names().

Add a lock around one remaining case of access to libcharset (the other
2 cases already have the lock).

Do a proper g_once_init_enter() style initialisation for the GLib
gettext functions.

https://bugzilla.gnome.org/show_bug.cgi?id=658683

glib/gconvert.c
glib/gthread.c
glib/gthreadprivate.h
glib/gutf8.c
glib/gutils.c

index c5845ca..86a2c0e 100644 (file)
@@ -1425,16 +1425,6 @@ get_filename_charset (const gchar **filename_charset)
   return is_utf8;
 }
 
-/* This is called from g_thread_init(). It's used to
- * initialize some static data in a threadsafe way.
- */
-void 
-_g_convert_thread_init (void)
-{
-  const gchar **dummy;
-  (void) g_get_filename_charsets (&dummy);
-}
-
 /**
  * g_filename_to_utf8:
  * @opsysstring:   a string in the encoding for filenames
index 26ff386..cc8e717 100644 (file)
@@ -957,10 +957,6 @@ g_thread_init_glib (void)
 
   /* accomplish log system initialization to enable messaging */
   _g_messages_thread_init_nomessage ();
-
-  /* we may run full-fledged initializers from here */
-  _g_convert_thread_init ();
-  _g_utils_thread_init ();
 }
 
 /* The following sections implement: GOnce, GStaticMutex, GStaticRecMutex,
index d0c8b33..3887519 100644 (file)
@@ -53,8 +53,6 @@ G_GNUC_INTERNAL void _g_slice_thread_init_nomessage       (void);
 G_GNUC_INTERNAL void _g_messages_thread_init_nomessage      (void);
 
 /* full fledged initializers */
-G_GNUC_INTERNAL void _g_convert_thread_init (void);
-G_GNUC_INTERNAL void _g_utils_thread_init (void);
 G_GNUC_INTERNAL void _g_thread_impl_init  (void);
 
 G_END_DECLS
index 7344e39..f6d721b 100644 (file)
@@ -597,7 +597,9 @@ g_get_charset (const char **charset)
       g_static_private_set (&cache_private, cache, charset_cache_free);
     }
 
+  G_LOCK (aliases);
   raw = _g_locale_charset_raw ();
+  G_UNLOCK (aliases);
   
   if (!(cache->raw && strcmp (cache->raw, raw) == 0))
     {
index 679bab7..162c2cf 100644 (file)
@@ -3648,15 +3648,6 @@ g_get_codeset (void)
   return g_strdup (charset);
 }
 
-/* This is called from g_thread_init(). It's used to
- * initialize some static data in a threadsafe way.
- */
-void
-_g_utils_thread_init (void)
-{
-  g_get_language_names ();
-}
-
 #ifdef G_OS_WIN32
 
 /**
@@ -3707,11 +3698,13 @@ _glib_get_locale_dir (void)
 #endif /* G_OS_WIN32 */
 
 static void
-ensure_gettext_initialized(void)
+ensure_gettext_initialized (void)
 {
-  static gboolean _glib_gettext_initialized = FALSE;
+  static gsize initialised;
 
-  if (!_glib_gettext_initialized)
+  g_thread_init_glib ();
+
+  if (g_once_init_enter (&initialised))
     {
 #ifdef G_OS_WIN32
       gchar *tmp = _glib_get_locale_dir ();
@@ -3723,7 +3716,7 @@ ensure_gettext_initialized(void)
 #    ifdef HAVE_BIND_TEXTDOMAIN_CODESET
       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 #    endif
-      _glib_gettext_initialized = TRUE;
+      g_once_init_leave (&initialised, TRUE);
     }
 }