Re: cache G_BROKEN_FILENAMES



On Sun, 10 Mar 2002, Owen Taylor wrote:

> 
> Alex Larsson <alexl redhat com> writes:
> 
> > Caching the value of getenv("G_BROKEN_FILENAMES") helps nautilus 
> > performance some (getenv showed up as number two in the profile)
> 
> Thread safety problems here. You could either:
>  
>  a) Add locking 
>  b) Arrange for g_thread_init()to call have_broken_filenames.

What about this? (does b)

Index: glib/gconvert.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gconvert.c,v
retrieving revision 1.34
diff -u -p -r1.34 gconvert.c
--- glib/gconvert.c	8 Mar 2002 15:50:53 -0000	1.34
+++ glib/gconvert.c	11 Mar 2002 00:04:01 -0000
@@ -1189,6 +1189,35 @@ g_locale_from_utf8 (const gchar *utf8str
 #endif /* !G_PLATFORM_WIN32 */
 }
 
+#ifndef G_PLATFORM_WIN32
+static gboolean
+have_broken_filenames (void)
+{
+  static gboolean initialized = FALSE;
+  static gboolean broken;
+  
+  if (initialized)
+    return broken;
+
+  broken = (getenv ("G_BROKEN_FILENAMES") != NULL);
+  
+  initialized = TRUE;
+  
+  return broken;
+}
+#endif /* !G_PLATFORM_WIN32 */
+
+/* This is called from g_thread_init(). It's used to
+ * initialize some static data in a threadsafe way.
+ */
+void 
+g_convert_init (void)
+{
+#ifndef G_PLATFORM_WIN32
+  have_broken_filenames ();
+#endif /* !G_PLATFORM_WIN32 */
+}
+
 /**
  * g_filename_to_utf8:
  * @opsysstring:   a string in the encoding for filenames
@@ -1225,7 +1254,7 @@ g_filename_to_utf8 (const gchar *opsysst
 			   error);
 #else  /* !G_PLATFORM_WIN32 */
       
-  if (getenv ("G_BROKEN_FILENAMES"))
+  if (have_broken_filenames ())
     return g_locale_to_utf8 (opsysstring, len,
 			     bytes_read, bytes_written,
 			     error);
@@ -1268,7 +1297,7 @@ g_filename_from_utf8 (const gchar *utf8s
 			     bytes_read, bytes_written,
 			     error);
 #else  /* !G_PLATFORM_WIN32 */
-  if (getenv ("G_BROKEN_FILENAMES"))
+  if (have_broken_filenames ())
     return g_locale_from_utf8 (utf8string, len,
 			       bytes_read, bytes_written,
 			       error);
Index: gthread/gthread-impl.c
===================================================================
RCS file: /cvs/gnome/glib/gthread/gthread-impl.c,v
retrieving revision 1.18
diff -u -p -r1.18 gthread-impl.c
--- gthread/gthread-impl.c	9 Feb 2002 20:23:01 -0000	1.18
+++ gthread/gthread-impl.c	11 Mar 2002 00:04:03 -0000
@@ -65,6 +65,7 @@ static gint g_thread_priority_map [G_THR
 void g_mutex_init (void);
 void g_mem_init (void);
 void g_messages_init (void);
+void g_convert_init (void);
 
 #define G_MUTEX_DEBUG_INFO(mutex) (*((gpointer*)(((char*)mutex)+G_MUTEX_SIZE)))
 
@@ -379,6 +380,7 @@ g_thread_init (GThreadFunctions* init)
   g_mutex_init ();
   g_mem_init ();
   g_messages_init ();
+  g_convert_init ();
 
   /* now we can set g_threads_got_initialized and thus enable
    * all the thread functions
 


-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a world-famous pirate cop who must take medication to keep him sane. 
She's a vivacious gold-digging socialite with the power to bend men's minds. 
They fight crime! 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]