From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id B634E385782C; Thu, 2 Dec 2021 16:53:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B634E385782C MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-5753] libstdc++: Restore unconditional atomic load in COW std::string X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: d08236359eb22918ba067489edcec02857109d09 X-Git-Newrev: b5a568683f71b4a8b1e4e45a43484398e9a66ff2 Message-Id: <20211202165341.B634E385782C@sourceware.org> Date: Thu, 2 Dec 2021 16:53:41 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Dec 2021 16:53:41 -0000 https://gcc.gnu.org/g:b5a568683f71b4a8b1e4e45a43484398e9a66ff2 commit r12-5753-gb5a568683f71b4a8b1e4e45a43484398e9a66ff2 Author: Jonathan Wakely Date: Wed Dec 1 20:58:58 2021 +0000 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: --- libstdc++-v3/include/bits/cow_string.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/bits/cow_string.h b/libstdc++-v3/include/bits/cow_string.h index d6ddf3489d1..389b39583e4 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