Patch ping

Ian Lance Taylor ian@airs.com
Fri Oct 7 22:07:00 GMT 2005


Paolo Carlini <pcarlini@suse.de> writes:

> Guys, thanks a lot for the nice ideas, but remember that we have first
> to figure out something for the short/mid term: for one, we don't have
> the compare_and_swap primitive implemented for all the targets and, for
> some, it will *never* be (i386, etc). Nothing new...

Sad but true.

> I believe in this *specific* case we can at least use mutexes without
> penalizing performances.

I'm testing this patch.

Ian

Index: config/linker-map.gnu
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/linker-map.gnu,v
retrieving revision 1.85
diff -p -u -r1.85 linker-map.gnu
--- config/linker-map.gnu	12 Sep 2005 04:49:09 -0000	1.85
+++ config/linker-map.gnu	7 Oct 2005 22:05:31 -0000
@@ -84,7 +84,7 @@ GLIBCXX_3.4 {
       std::locale::[A-Zj-z]*;
       std::locale::_[A-Ha-z]*;
       std::locale::_Impl::[A-Za-z]*;
-      std::locale::_Impl::_M_[A-Za-z]*;
+#     std::locale::_Impl::_M_[A-Za-z]*;
       std::locale::_[J-Ra-z]*;
       std::locale::_S_normalize_category*;
       std::locale::_[T-Za-z]*;
@@ -468,6 +468,12 @@ GLIBCXX_3.4 {
 
     _ZNSt19istreambuf_iteratorI[cw]St11char_traitsI[cw]EEppEv;
 
+    # std::locale::Impl _M_ members
+    _ZNSt6locale5_Impl16_M_install_facetEPKNS_2idEPKNS_5facetE;
+    _ZNSt6locale5_Impl16_M_replace_facetEPKS0_PKNS_2idE;
+    _ZNSt6locale5_Impl19_M_replace_categoryEPKS0_PKPKNS_2idE;
+    _ZNSt6locale5_Impl21_M_replace_categoriesEPKS0_i;
+
   # DO NOT DELETE THIS LINE.  Port-specific symbols, if any, will be here.
 
   local:
@@ -571,7 +577,9 @@ GLIBCXX_3.4.6 {
 
     _ZNKSt15basic_stringbufIwSt11char_traitsIwESaIwEE3strEv;
 
-   _ZN9__gnu_cxx6__poolILb1EE13_M_initializeEv;
+    _ZN9__gnu_cxx6__poolILb1EE13_M_initializeEv;
+
+    _ZNSt6locale5_Impl16_M_install_cacheEPKNS_5facetEj;
 
 } GLIBCXX_3.4.5;
 
Index: include/bits/locale_classes.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_classes.h,v
retrieving revision 1.25
diff -p -u -r1.25 locale_classes.h
--- include/bits/locale_classes.h	17 Aug 2005 02:12:52 -0000	1.25
+++ include/bits/locale_classes.h	7 Oct 2005 22:05:35 -0000
@@ -559,11 +559,7 @@ namespace std
       { _M_install_facet(&_Facet::id, __facet); }
 
     void
-    _M_install_cache(const facet* __cache, size_t __index) throw()
-    {
-      __cache->_M_add_reference();
-      _M_caches[__index] = __cache;
-    }
+    _M_install_cache(const facet* __cache, size_t __index);
   };
 
   template<typename _Facet>
Index: src/locale.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/locale.cc,v
retrieving revision 1.111
diff -p -u -r1.111 locale.cc
--- src/locale.cc	17 Aug 2005 02:14:22 -0000	1.111
+++ src/locale.cc	7 Oct 2005 22:05:39 -0000
@@ -33,6 +33,13 @@
 #include <cwctype>     // For towupper, etc.
 #include <locale>
 #include <bits/atomicity.h>
+#include <bits/concurrence.h>
+
+namespace __gnu_internal
+{
+  // Mutex object for cache access
+  static __glibcxx_mutex_define_initialized(locale_cache_mutex);
+}
 
 namespace std 
 {
@@ -366,6 +373,23 @@ namespace std 
       }
   }
 
+  void
+  locale::_Impl::
+  _M_install_cache(const facet* __cache, size_t __index)
+  {
+    __gnu_cxx::lock sentry(__gnu_internal::locale_cache_mutex);
+    if (_M_caches[__index] != 0)
+      {
+	// Some other thread got in first.
+	delete __cache;
+      }
+    else
+      {
+	__cache->_M_add_reference();
+	_M_caches[__index] = __cache;
+      }
+  }
+
   // locale::id
   // Definitions for static const data members of locale::id
   _Atomic_word locale::id::_S_refcount;  // init'd to 0 by linker



More information about the Libstdc++ mailing list