From: Jonathan Wakely Date: Wed, 1 Dec 2021 20:58:58 +0000 (+0000) Subject: libstdc++: Restore unconditional atomic load in COW std::string X-Git-Tag: basepoints/gcc-13~2560 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5a568683f71b4a8b1e4e45a43484398e9a66ff2;p=thirdparty%2Fgcc.git libstdc++: Restore unconditional atomic load in COW std::string 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. --- diff --git a/libstdc++-v3/include/bits/cow_string.h b/libstdc++-v3/include/bits/cow_string.h index d6ddf3489d1a..389b39583e47 100644 --- a/libstdc++-v3/include/bits/cow_string.h +++ b/libstdc++-v3/include/bits/cow_string.h @@ -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