This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] libstdc++/29496


Hi,

various versions tested x86/ia64-linux, committed to mainline.

Paolo.

////////////////////
2006-11-11  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/29496
	* include/debug/safe_base.h (_Safe_sequence_base::_M_get_mutex,
	_Safe_iterator_base::_M_get_mutex, _M_attach_single, _M_detach_single):
	New.
	* src/debug.cc: Define the latter.
	(_Safe_sequence_base::_M_detach_all, _M_detach_singular,
	_M_revalidate_singular, _M_swap): Use the mutex.
	(_Safe_iterator_base::_M_attach, _M_detach): Adjust, forward to the
	*_single version.
	* include/debug/safe_iterator.h (_Safe_iterator<>::_M_attach_single,
	_M_invalidate_single): New.
 	* include/debug/safe_iterator.tcc: Define.
	(_Safe_iterator<>::_M_invalidate): Adjust, forward to
	_M_invalidate_single.
	* include/debug/safe_sequence.h (_Safe_sequence<>::_M_invalidate_if,
	_M_transfer_iter): Use the mutex, adjust, forward to the *_single
	versions of _M_invalidate and _M_attach.
	* config/abi/pre/gnu.ver (_Safe_sequence_base::_M_get_mutex,
	_Safe_iterator_base::_M_get_mutex, _M_attach_single, _M_detach_single):
	Add @GLIBCXX_3.4.10; adjust.
	* configure.ac (libtool_VERSION): To 6:10:0.
	* testsuite/util/testsuite_abi.cc (check_version): Add GLIBCXX_3.4.10.
	* configure: Regenerate.
Index: include/debug/safe_sequence.h
===================================================================
--- include/debug/safe_sequence.h	(revision 118663)
+++ include/debug/safe_sequence.h	(working copy)
@@ -124,27 +124,28 @@
         typedef typename _Sequence::iterator iterator;
         typedef typename _Sequence::const_iterator const_iterator;
 
-        for (_Safe_iterator_base* __iter = _M_iterators; __iter; )
-        {
-          iterator* __victim = static_cast<iterator*>(__iter);
-          __iter = __iter->_M_next;
-          if (!__victim->_M_singular())
-          {
-	    if (__pred(__victim->base()))
-	      __victim->_M_invalidate();
-          }
-        }
+	__gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
+        for (_Safe_iterator_base* __iter = _M_iterators; __iter;)
+	  {
+	    iterator* __victim = static_cast<iterator*>(__iter);
+	    __iter = __iter->_M_next;
+	    if (!__victim->_M_singular())
+	      {
+		if (__pred(__victim->base()))
+		  __victim->_M_invalidate_single();
+	      }
+	  }
 
-        for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2; )
-        {
-          const_iterator* __victim = static_cast<const_iterator*>(__iter2);
-          __iter2 = __iter2->_M_next;
-          if (!__victim->_M_singular())
-          {
-	    if (__pred(__victim->base()))
-	      __victim->_M_invalidate();
-          }
-        }
+        for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2;)
+	  {
+	    const_iterator* __victim = static_cast<const_iterator*>(__iter2);
+	    __iter2 = __iter2->_M_next;
+	    if (!__victim->_M_singular())
+	      {
+		if (__pred(__victim->base()))
+		  __victim->_M_invalidate_single();
+	      }
+	  }
       }
 
   template<typename _Sequence>
@@ -160,22 +161,23 @@
         typedef typename _Sequence::iterator iterator;
         typedef typename _Sequence::const_iterator const_iterator;
 
-        for (_Safe_iterator_base* __iter = __from->_M_iterators; __iter; )
-        {
-          iterator* __victim = static_cast<iterator*>(__iter);
-          __iter = __iter->_M_next;
-          if (!__victim->_M_singular() && __victim->base() == __x.base())
-	    __victim->_M_attach(static_cast<_Sequence*>(this));
-        }
+	__gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
+        for (_Safe_iterator_base* __iter = __from->_M_iterators; __iter;)
+	  {
+	    iterator* __victim = static_cast<iterator*>(__iter);
+	    __iter = __iter->_M_next;
+	    if (!__victim->_M_singular() && __victim->base() == __x.base())
+	      __victim->_M_attach_single(static_cast<_Sequence*>(this));
+	  }
 
         for (_Safe_iterator_base* __iter2 = __from->_M_const_iterators; 
 	     __iter2;)
-        {
-          const_iterator* __victim = static_cast<const_iterator*>(__iter2);
-          __iter2 = __iter2->_M_next;
-          if (!__victim->_M_singular() && __victim->base() == __x.base())
-	    __victim->_M_attach(static_cast<_Sequence*>(this));
-        }
+	  {
+	    const_iterator* __victim = static_cast<const_iterator*>(__iter2);
+	    __iter2 = __iter2->_M_next;
+	    if (!__victim->_M_singular() && __victim->base() == __x.base())
+	      __victim->_M_attach_single(static_cast<_Sequence*>(this));
+	  }
       }
 } // namespace __gnu_debug
 
Index: include/debug/safe_base.h
===================================================================
--- include/debug/safe_base.h	(revision 118663)
+++ include/debug/safe_base.h	(working copy)
@@ -31,6 +31,8 @@
 #ifndef _GLIBCXX_DEBUG_SAFE_BASE_H
 #define _GLIBCXX_DEBUG_SAFE_BASE_H 1
 
+#include <ext/concurrence.h>
+
 namespace __gnu_debug
 {
   class _Safe_sequence_base;
@@ -103,6 +105,9 @@
 
     ~_Safe_iterator_base() { this->_M_detach(); }
 
+    /** For use in _Safe_iterator. */
+    __gnu_cxx::__mutex& _M_get_mutex();
+
   public:
     /** Attaches this iterator to the given sequence, detaching it
      *	from whatever sequence it was attached to originally. If the
@@ -111,11 +116,17 @@
      */
     void _M_attach(_Safe_sequence_base* __seq, bool __constant);
 
+    /** Likewise, but not thread-safe. */
+    void _M_attach_single(_Safe_sequence_base* __seq, bool __constant);
+
     /** Detach the iterator for whatever sequence it is attached to,
      *	if any.
     */
     void _M_detach();
 
+    /** Likewise, but not thread-safe. */
+    void _M_detach_single();
+
     /** Determines if we are attached to the given sequence. */
     bool _M_attached_to(const _Safe_sequence_base* __seq) const
     { return _M_sequence == __seq; }
@@ -196,6 +207,9 @@
     void
     _M_swap(_Safe_sequence_base& __x);
 
+    /** For use in _Safe_sequence. */
+    __gnu_cxx::__mutex& _M_get_mutex();
+
   public:
     /** Invalidates all iterators. */
     void
Index: include/debug/safe_iterator.tcc
===================================================================
--- include/debug/safe_iterator.tcc	(revision 118663)
+++ include/debug/safe_iterator.tcc	(working copy)
@@ -111,23 +111,32 @@
     _Safe_iterator<_Iterator, _Sequence>::
     _M_invalidate()
     {
+      __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
+      _M_invalidate_single();
+    }
+
+  template<typename _Iterator, typename _Sequence>
+    void
+    _Safe_iterator<_Iterator, _Sequence>::
+    _M_invalidate_single()
+    {
       typedef typename _Sequence::iterator iterator;
       typedef typename _Sequence::const_iterator const_iterator;
 
       if (!this->_M_singular())
 	{
-	  for (_Safe_iterator_base* iter = _M_sequence->_M_iterators; iter;)
+	  for (_Safe_iterator_base* __iter = _M_sequence->_M_iterators;
+	       __iter; __iter = __iter->_M_next)
 	    {
-	      iterator* __victim = static_cast<iterator*>(iter);
-	      iter = iter->_M_next;
+	      iterator* __victim = static_cast<iterator*>(__iter);
 	      if (this->base() == __victim->base())
 		__victim->_M_version = 0;
 	    }
-	  for (_Safe_iterator_base* iter = _M_sequence->_M_const_iterators;
-	       iter;)
+
+	  for (_Safe_iterator_base* __iter2 = _M_sequence->_M_const_iterators;
+	       __iter2; __iter2 = __iter2->_M_next)
 	    {
-	      const_iterator* __victim = static_cast<const_iterator*>(iter);
-	      iter = iter->_M_next;
+	      const_iterator* __victim = static_cast<const_iterator*>(__iter2);
 	      if (__victim->base() == this->base())
 		__victim->_M_version = 0;
 	    }
Index: include/debug/safe_iterator.h
===================================================================
--- include/debug/safe_iterator.h	(revision 118663)
+++ include/debug/safe_iterator.h	(working copy)
@@ -321,10 +321,22 @@
 				       _M_constant());
       }
 
+      /** Likewise, but not thread-safe. */
+      void
+      _M_attach_single(const _Sequence* __seq)
+      {
+	_Safe_iterator_base::_M_attach_single(const_cast<_Sequence*>(__seq),
+					      _M_constant());
+      }
+
       /** Invalidate the iterator, making it singular. */
       void
       _M_invalidate();
 
+      /** Likewise, but not thread-safe. */
+      void
+      _M_invalidate_single();
+
       /// Is the iterator dereferenceable?
       bool
       _M_dereferenceable() const
Index: src/debug.cc
===================================================================
--- src/debug.cc	(revision 118663)
+++ src/debug.cc	(working copy)
@@ -35,13 +35,12 @@
 #include <cassert>
 #include <cstring>
 #include <cctype>
-#include <ext/concurrence.h>
 
 using namespace std;
 
 namespace
 {
-  __gnu_cxx::__mutex iterator_base_mutex;
+  __gnu_cxx::__mutex safe_base_mutex;
 } // anonymous namespace
 
 namespace __gnu_debug
@@ -107,43 +106,45 @@
     "attempt to increment an end-of-stream istreambuf_iterator"
   };
 
-  void 
+  void
   _Safe_sequence_base::
   _M_detach_all()
   {
-    for (_Safe_iterator_base* __iter = _M_iterators; __iter; )
+    __gnu_cxx::__scoped_lock sentry(safe_base_mutex);
+    for (_Safe_iterator_base* __iter = _M_iterators; __iter;)
       {
 	_Safe_iterator_base* __old = __iter;
 	__iter = __iter->_M_next;
-	__old->_M_attach(0, false);
+	__old->_M_detach_single();
       }
     
-    for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2; )
+    for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2;)
       {
 	_Safe_iterator_base* __old = __iter2;
 	__iter2 = __iter2->_M_next;
-	__old->_M_attach(0, true);
+	__old->_M_detach_single();
       }
   }
 
-  void 
+  void
   _Safe_sequence_base::
   _M_detach_singular()
   {
-    for (_Safe_iterator_base* __iter = _M_iterators; __iter; )
+    __gnu_cxx::__scoped_lock sentry(safe_base_mutex);
+    for (_Safe_iterator_base* __iter = _M_iterators; __iter;)
       {
 	_Safe_iterator_base* __old = __iter;
 	__iter = __iter->_M_next;
 	if (__old->_M_singular())
-	  __old->_M_attach(0, false);
+	  __old->_M_detach_single();
       }
 
-    for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2; )
+    for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2;)
       {
 	_Safe_iterator_base* __old = __iter2;
 	__iter2 = __iter2->_M_next;
 	if (__old->_M_singular())
-	  __old->_M_attach(0, true);
+	  __old->_M_detach_single();
       }
   }
 
@@ -151,6 +152,7 @@
   _Safe_sequence_base::
   _M_revalidate_singular()
   {
+    __gnu_cxx::__scoped_lock sentry(safe_base_mutex);
     for (_Safe_iterator_base* __iter = _M_iterators; __iter;
 	 __iter = __iter->_M_next)
       __iter->_M_version = _M_version;
@@ -160,10 +162,11 @@
       __iter2->_M_version = _M_version;
   }
 
-  void 
+  void
   _Safe_sequence_base::
   _M_swap(_Safe_sequence_base& __x)
   {
+    __gnu_cxx::__scoped_lock sentry(safe_base_mutex);
     swap(_M_iterators, __x._M_iterators);
     swap(_M_const_iterators, __x._M_const_iterators);
     swap(_M_version, __x._M_version);
@@ -177,17 +180,29 @@
     for (__iter = __x._M_const_iterators; __iter; __iter = __iter->_M_next)
       __iter->_M_sequence = &__x;
   }
-  
-  void 
+
+  __gnu_cxx::__mutex&
+  _Safe_sequence_base::
+  _M_get_mutex()
+  { return safe_base_mutex; }
+
+  void
   _Safe_iterator_base::
   _M_attach(_Safe_sequence_base* __seq, bool __constant)
   {
-    _M_detach();
+    __gnu_cxx::__scoped_lock sentry(safe_base_mutex);
+    _M_attach_single(__seq, __constant);
+  }
+  
+  void
+  _Safe_iterator_base::
+  _M_attach_single(_Safe_sequence_base* __seq, bool __constant)
+  {
+    _M_detach_single();
     
     // Attach to the new sequence (if there is one)
     if (__seq)
       {
-	__gnu_cxx::__scoped_lock sentry(iterator_base_mutex);
 	_M_sequence = __seq;
 	_M_version = _M_sequence->_M_version;
 	_M_prior = 0;
@@ -208,11 +223,18 @@
       }
   }
 
-  void 
+  void
   _Safe_iterator_base::
   _M_detach()
   {
-    __gnu_cxx::__scoped_lock sentry(iterator_base_mutex);
+    __gnu_cxx::__scoped_lock sentry(safe_base_mutex);
+    _M_detach_single();
+  }
+
+  void
+  _Safe_iterator_base::
+  _M_detach_single()
+  {
     if (_M_sequence)
       {
 	// Remove us from this sequence's list
@@ -232,7 +254,7 @@
     _M_prior = 0;
     _M_next = 0;
   }
-  
+
   bool
   _Safe_iterator_base::
   _M_singular() const
@@ -246,6 +268,11 @@
 	    && !__x._M_singular() && _M_sequence == __x._M_sequence);
   }
 
+  __gnu_cxx::__mutex&
+  _Safe_iterator_base::
+  _M_get_mutex()
+  { return safe_base_mutex; }
+
   void
   _Error_formatter::_Parameter::
   _M_print_field(const _Error_formatter* __formatter, const char* __name) const
Index: testsuite/util/testsuite_abi.cc
===================================================================
--- testsuite/util/testsuite_abi.cc	(revision 118663)
+++ testsuite/util/testsuite_abi.cc	(working copy)
@@ -188,6 +188,7 @@
       known_versions.push_back("GLIBCXX_3.4.7");
       known_versions.push_back("GLIBCXX_3.4.8");
       known_versions.push_back("GLIBCXX_3.4.9");
+      known_versions.push_back("GLIBCXX_3.4.10");
       known_versions.push_back("GLIBCXX_LDBL_3.4");
       known_versions.push_back("GLIBCXX_LDBL_3.4.7");
       known_versions.push_back("CXXABI_1.3");
Index: configure.ac
===================================================================
--- configure.ac	(revision 118663)
+++ configure.ac	(working copy)
@@ -12,7 +12,7 @@
 ### am handles this now?  ORIGINAL_LD_FOR_MULTILIBS=$LD
 
 # For libtool versioning info, format is CURRENT:REVISION:AGE
-libtool_VERSION=6:9:0
+libtool_VERSION=6:10:0
 AC_SUBST(libtool_VERSION)
 
 # Find the rest of the source tree framework.
Index: config/abi/pre/gnu.ver
===================================================================
--- config/abi/pre/gnu.ver	(revision 118663)
+++ config/abi/pre/gnu.ver	(working copy)
@@ -120,13 +120,21 @@
       std::__moneypunct_cache*;
       std::__numpunct_cache*;
       std::__timepunct_cache*;
-      __gnu_debug::_Safe_iterator_base*;
-      __gnu_debug::_Safe_sequence_base*;
       __gnu_debug::_Error_formatter*
     };
 
     # Names not in an 'extern' block are mangled names.
 
+    # __gnu_debug::_Safe_sequence_base and _Safe_iterator_base
+    _ZN11__gnu_debug19_Safe_sequence_base13_M_detach_allEv;
+    _ZN11__gnu_debug19_Safe_sequence_base18_M_detach_singularEv;
+    _ZN11__gnu_debug19_Safe_sequence_base22_M_revalidate_singularEv;
+    _ZN11__gnu_debug19_Safe_sequence_base7_M_swapERS0_;
+    _ZN11__gnu_debug19_Safe_iterator_base9_M_attachEPNS_19_Safe_sequence_baseEb;
+    _ZN11__gnu_debug19_Safe_iterator_base9_M_detachEv;
+    _ZNK11__gnu_debug19_Safe_iterator_base11_M_singularEv;
+    _ZNK11__gnu_debug19_Safe_iterator_base14_M_can_compareERKS0_;
+
     # std::string
     _ZNSsC*;
     _ZNSsD*;
@@ -662,9 +670,18 @@
 
     _ZNSo9_M_insertEPKc[il];
     _ZNSt13basic_ostreamIwSt11char_traitsIwEE9_M_insertEPKw[il];
+
 } GLIBCXX_3.4.8;
 
+GLIBCXX_3.4.10 {
 
+    _ZN11__gnu_debug19_Safe_sequence_base12_M_get_mutexEv;
+    _ZN11__gnu_debug19_Safe_iterator_base16_M_attach_singleEPNS_19_Safe_sequence_baseEb;
+    _ZN11__gnu_debug19_Safe_iterator_base16_M_detach_singleEv;
+    _ZN11__gnu_debug19_Safe_iterator_base12_M_get_mutexEv;
+
+} GLIBCXX_3.4.9;
+
 # Symbols in the support library (libsupc++) have their own tag.
 CXXABI_1.3 {
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]