]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Restore unconditional atomic load in COW std::string
authorJonathan Wakely <jwakely@redhat.com>
Wed, 1 Dec 2021 20:58:58 +0000 (20:58 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 2 Dec 2021 16:46:28 +0000 (16:46 +0000)
The relaxed load is already optimal, checking the __single_threaded
global before doing a non-atomic load isn't an optimization.

libstdc++-v3/ChangeLog:

* include/bits/cow_string.h (basic_string::_M_is_leaked()):
Revert change to check __is_single_threaded() before using
atomic load.

libstdc++-v3/include/bits/cow_string.h

index d6ddf3489d1aca5efefb7dec728c6f80653956ae..389b39583e476c25a1e6b86d371e23532d332354 100644 (file)
@@ -207,10 +207,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          // so we need to use an atomic load. However, _M_is_leaked
          // predicate does not change concurrently (i.e. the string is either
          // leaked or not), so a relaxed load is enough.
-         if (!__gnu_cxx::__is_single_threaded())
-           return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
-#endif
+         return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
+#else
          return this->_M_refcount < 0;
+#endif
        }
 
        bool