]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/24704 (__gnu_cxx::__exchange_and_add is called even for single thread...
authorPaolo Carlini <pcarlini@suse.de>
Wed, 24 May 2006 16:37:42 +0000 (16:37 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 24 May 2006 16:37:42 +0000 (16:37 +0000)
2006-05-24  Paolo Carlini  <pcarlini@suse.de>

PR libstdc++/24704
* include/bits/atomicity.h (__exchange_and_add_single,
__atomic_add_single): New, single thread versions of the atomic
functions.
(__exchange_and_add_dispatch, __atomic_add_dispatch): New,
depending on __GTHREADS and __gthread_active_p() dispatch either
to the above or to the existing atomic functions.
* include/ext/pool_allocator.h: Update callers.
* include/ext/rc_string_base.h: Likewise.
* include/bits/locale_classes.h: Likewise.
* include/bits/basic_string.h: Likewise.
* include/bits/ios_base.h: Likewise.
* include/tr1/boost_shared_ptr.h: Likewise.
* src/ios.cc: Likewise.
* src/locale.cc: Likewise.
* src/ios_init.cc: Likewise.

From-SVN: r114044

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/atomicity.h
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/ios_base.h
libstdc++-v3/include/bits/locale_classes.h
libstdc++-v3/include/ext/pool_allocator.h
libstdc++-v3/include/ext/rc_string_base.h
libstdc++-v3/include/tr1/boost_shared_ptr.h
libstdc++-v3/src/ios.cc
libstdc++-v3/src/ios_init.cc
libstdc++-v3/src/locale.cc

index 7d008bf89197f89bd9d58a083a3eed72ff7fe785..21e4f00c03a163bd1c6abb7d77c4a34f8f46d045 100644 (file)
@@ -1,3 +1,22 @@
+2006-05-24  Paolo Carlini  <pcarlini@suse.de>
+
+       PR libstdc++/24704
+       * include/bits/atomicity.h (__exchange_and_add_single,
+       __atomic_add_single): New, single thread versions of the atomic
+       functions.
+       (__exchange_and_add_dispatch, __atomic_add_dispatch): New,
+       depending on __GTHREADS and __gthread_active_p() dispatch either
+       to the above or to the existing atomic functions.
+       * include/ext/pool_allocator.h: Update callers.
+       * include/ext/rc_string_base.h: Likewise.
+       * include/bits/locale_classes.h: Likewise.
+       * include/bits/basic_string.h: Likewise.
+       * include/bits/ios_base.h: Likewise.
+       * include/tr1/boost_shared_ptr.h: Likewise.
+       * src/ios.cc: Likewise.
+       * src/locale.cc: Likewise.
+       * src/ios_init.cc: Likewise.
+
 2006-05-23  Paolo Carlini  <pcarlini@suse.de>
 
        * testsuite/testsuite_shared.cc: Fix --enable-threads=single build.
index f436e0bdc0035106bb22d856dc2a07e3bb9d8cc2..53ab6fad7034525d49eb809c06a6f8001987033d 100644 (file)
@@ -1,6 +1,6 @@
 // Low-level functions for atomic operations -*- C++ -*-
 
-// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 #define _GLIBCXX_ATOMICITY_H   1
 
 #include <bits/c++config.h>
+#include <bits/gthr.h>
 #include <bits/atomic_word.h>
 
 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
 
-  _Atomic_word 
+  _Atomic_word
   __attribute__ ((__unused__))
   __exchange_and_add(volatile _Atomic_word* __mem, int __val);
 
@@ -48,6 +49,54 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
   __attribute__ ((__unused__))
   __atomic_add(volatile _Atomic_word* __mem, int __val);
 
+  static inline _Atomic_word
+  __exchange_and_add_single(volatile _Atomic_word* __mem, int __val)
+  {
+    _Atomic_word __result = *__mem;
+    *__mem += __val;
+    return __result;
+  }
+
+  static inline void
+  __atomic_add_single(volatile _Atomic_word* __mem, int __val)
+  { *__mem += __val; }
+
+  static inline _Atomic_word
+  __attribute__ ((__unused__))
+  __exchange_and_add_dispatch(volatile _Atomic_word* __mem, int __val)
+  {
+#ifdef __GTHREADS
+
+    if (__gthread_active_p())
+      return __exchange_and_add(__mem, __val);
+    else
+      return __exchange_and_add_single(__mem, __val);
+
+#else
+
+    return __exchange_and_add_single(__mem, __val);
+
+#endif
+  }
+
+  static inline void
+  __attribute__ ((__unused__))
+  __atomic_add_dispatch(volatile _Atomic_word* __mem, int __val)
+  {
+#ifdef __GTHREADS
+
+    if (__gthread_active_p())
+      __atomic_add(__mem, __val);
+    else
+      __atomic_add_single(__mem, __val);
+
+#else
+
+    __atomic_add_single(__mem, __val);
+
+#endif
+  }
+
 _GLIBCXX_END_NAMESPACE
 
 /* Even if the CPU doesn't need a memory barrier, we need to ensure that
index acd2f144e818a61786d9bd7e1af8b4cdb595948b..4a703ce2b1076f9d23ccd58b14ed091797dbd590 100644 (file)
@@ -1,6 +1,6 @@
 // Components for manipulating sequences of characters -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -232,7 +232,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
          if (__builtin_expect(this != &_S_empty_rep(), false))
 #endif
-           if (__gnu_cxx::__exchange_and_add(&this->_M_refcount, -1) <= 0)
+           if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
+                                                      -1) <= 0)
              _M_destroy(__a);
        }  // XXX MT
 
@@ -245,7 +246,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
          if (__builtin_expect(this != &_S_empty_rep(), false))
 #endif
-            __gnu_cxx::__atomic_add(&this->_M_refcount, 1);
+            __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
          return _M_refdata();
        }  // XXX MT
 
index 9b695079d7da40f0916add5f5ef65b55785c1d3c..dbaa74d87c05b97ad0f2206d8268d81be9c6370a 100644 (file)
@@ -476,12 +476,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
 
       void
-      _M_add_reference() { __gnu_cxx::__atomic_add(&_M_refcount, 1); }
+      _M_add_reference() { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
 
       // 0 => OK to delete.
       int
       _M_remove_reference() 
-      { return __gnu_cxx::__exchange_and_add(&_M_refcount, -1); }
+      { return __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1); }
     };
 
      _Callback_list*   _M_callbacks;
index f72b72ab669a8ca760b9a037532791f39f39c8b0..ab5efb7466fde796ac242734ab8d9e7206ee3754 100644 (file)
@@ -400,12 +400,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
   private:
     inline void
     _M_add_reference() const throw()
-    { __gnu_cxx::__atomic_add(&_M_refcount, 1); }
+    { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
 
     inline void
     _M_remove_reference() const throw()
     {
-      if (__gnu_cxx::__exchange_and_add(&_M_refcount, -1) == 1)
+      if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
        {
          try
            { delete this; }
@@ -505,12 +505,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
     inline void
     _M_add_reference() throw()
-    { __gnu_cxx::__atomic_add(&_M_refcount, 1); }
+    { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
 
     inline void
     _M_remove_reference() throw()
     {
-      if (__gnu_cxx::__exchange_and_add(&_M_refcount, -1) == 1)
+      if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
        {
          try
            { delete this; }
index 0d6333660036cbd87f0d923c7a73d64697e343f7..d12831018ce9f4fa5be05def0d7b5042f83b7c7d 100644 (file)
@@ -206,9 +206,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
          if (_S_force_new == 0)
            {
              if (std::getenv("GLIBCXX_FORCE_NEW"))
-               __atomic_add(&_S_force_new, 1);
+               __atomic_add_dispatch(&_S_force_new, 1);
              else
-               __atomic_add(&_S_force_new, -1);
+               __atomic_add_dispatch(&_S_force_new, -1);
            }
 
          const size_t __bytes = __n * sizeof(_Tp);           
index dece887d1995fc1ece8dd6b81d15d62668e43416..c8bb9f3edcaed86880eb8445e981cd06e66440a2 100644 (file)
@@ -1,6 +1,6 @@
 // Reference-counted versatile string base -*- C++ -*-
 
-// Copyright (C) 2005 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -134,7 +134,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
        _CharT*
        _M_refcopy() throw()
        {
-         __atomic_add(&_M_info._M_refcount, 1);
+         __atomic_add_dispatch(&_M_info._M_refcount, 1);
          return _M_refdata();
        }  // XXX MT
        
@@ -202,7 +202,8 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
       void
       _M_dispose()
       {
-       if (__exchange_and_add(&_M_rep()->_M_info._M_refcount, -1) <= 0)
+       if (__exchange_and_add_dispatch(&_M_rep()->_M_info._M_refcount,
+                                       -1) <= 0)
          _M_rep()->_M_destroy(_M_get_allocator());
       }  // XXX MT
 
index e47c570c8817d9efe893e52f9014681cd0f36bb1..27f0e7a101e89275b037e1e48c64dad43ebe9877 100644 (file)
@@ -130,14 +130,14 @@ public:
   void
   add_ref_copy()
   {
-    __gnu_cxx::__atomic_add(&_M_use_count, 1);
+    __gnu_cxx::__atomic_add_dispatch(&_M_use_count, 1);
   }
 
   void
   add_ref_lock()
   {
     __gnu_cxx::lock lock(_M_mutex);
-    if (__gnu_cxx::__exchange_and_add(&_M_use_count, 1) == 0)
+    if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0)
       {
        _M_use_count = 0;
        __throw_bad_weak_ptr();
@@ -147,14 +147,14 @@ public:
   void
   release() // nothrow
   {
-    if (__gnu_cxx::__exchange_and_add(&_M_use_count, -1) == 1)
+    if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, -1) == 1)
       {
        dispose();
 #ifdef __GTHREADS      
        _GLIBCXX_READ_MEM_BARRIER;
        _GLIBCXX_WRITE_MEM_BARRIER;
 #endif
-       if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) == 1)
+       if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1)
          destroy();
       }
   }
@@ -162,13 +162,13 @@ public:
   void
   weak_add_ref() // nothrow
   {
-    __gnu_cxx::__atomic_add(&_M_weak_count, 1);
+    __gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1);
   }
 
   void
   weak_release() // nothrow
   {
-    if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) == 1)
+    if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1)
       {
 #ifdef __GTHREADS
        _GLIBCXX_READ_MEM_BARRIER;
index 5b05f283a853dea79d2f763900a6df12aa94dbca..e22c681e905faead8962b804e9d5e18320a87f09 100644 (file)
@@ -107,7 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     // Implementation note: Initialize top to zero to ensure that
     // initialization occurs before main() is started.
     static _Atomic_word _S_top = 0; 
-    return __gnu_cxx::__exchange_and_add(&_S_top, 1) + 4;
+    return __gnu_cxx::__exchange_and_add_dispatch(&_S_top, 1) + 4;
   }
 
   void 
index 93a39857bc7d1882dbd49606d16b97cfb7d6678a..680efddaabfbad96c4af2a41d5a580b897eb9c0c 100644 (file)
@@ -82,7 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
   ios_base::Init::Init()
   {
-    if (__gnu_cxx::__exchange_and_add(&_S_refcount, 1) == 0)
+    if (__gnu_cxx::__exchange_and_add_dispatch(&_S_refcount, 1) == 0)
       {
        // Standard streams default to synced with "C" operations.
        _S_synced_with_stdio = true;
@@ -121,13 +121,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        // streams are not re-initialized with uses of ios_base::Init
        // besides <iostream> static object, ie just using <ios> with
        // ios_base::Init objects.
-       __gnu_cxx::__atomic_add(&_S_refcount, 1);
+       __gnu_cxx::__atomic_add_dispatch(&_S_refcount, 1);
       }
   }
 
   ios_base::Init::~Init()
   {
-    if (__gnu_cxx::__exchange_and_add(&_S_refcount, -1) == 2)
+    if (__gnu_cxx::__exchange_and_add_dispatch(&_S_refcount, -1) == 2)
       {
        // Catch any exceptions thrown by basic_ostream::flush()
        try
index c56ec51909b16a82e8ce6b309b47938eade29b27..22d8ab0a6753dcc103fd040e771eede868618972 100644 (file)
@@ -433,7 +433,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
          _M_index = 1 + f->_M_id();
        else
 #endif
-         _M_index = 1 + __gnu_cxx::__exchange_and_add(&_S_refcount, 1);
+         _M_index = 1 + __gnu_cxx::__exchange_and_add_dispatch(&_S_refcount,
+                                                               1);
       }
     return _M_index - 1;
   }