diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-10-03 12:27:40 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-10-03 12:27:40 +0100 |
commit | 749c0e1d8b2c8dbc54af3365af506b3e1986e754 (patch) | |
tree | 08e082060cf8f5dbfadf13f7fa2bf8ab8121357f | |
parent | e7df9e44c68164cfdd0dcc8d848d480054c4e6b3 (diff) | |
download | gcc-749c0e1d8b2c8dbc54af3365af506b3e1986e754.zip gcc-749c0e1d8b2c8dbc54af3365af506b3e1986e754.tar.gz gcc-749c0e1d8b2c8dbc54af3365af506b3e1986e754.tar.bz2 |
PR libstdc++/59439 optimize uses of classic ("C") std::locale
The global locale::_Impl that represents the "C" locale is never
destroyed, so there is no need to keep track of reference count updates
for that object. This greatly reduce contention between threads that
refer to the classic locale. Since the global std::locale initially uses
the classic locale, this benefits the common case for any code using the
global locale, such as construction/destruction of iostream objects.
All these updates are done inside libstdc++.so so there's no need to
worry about users' objects having inlined old versions of the code which
still update the reference count for the classic locale.
PR libstdc++/59439
* src/c++98/locale.cc (locale::locale(const locale&)): Bypass
reference count updates for the classic locale.
(locale::~locale()): Likewise.
(locale::operator=(const locale&)): Likewise.
* src/c++98/locale_init.cc (locale::locale()): Likewise.
(locale::global(const locale&)): Likewise.
From-SVN: r264811
-rw-r--r-- | libstdc++-v3/ChangeLog | 10 | ||||
-rw-r--r-- | libstdc++-v3/src/c++98/locale.cc | 16 | ||||
-rw-r--r-- | libstdc++-v3/src/c++98/locale_init.cc | 9 |
3 files changed, 26 insertions, 9 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index fe0fbf7..84e61ca 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2018-10-03 Jonathan Wakely <jwakely@redhat.com> + + PR libstdc++/59439 + * src/c++98/locale.cc (locale::locale(const locale&)): Bypass + reference count updates for the classic locale. + (locale::~locale()): Likewise. + (locale::operator=(const locale&)): Likewise. + * src/c++98/locale_init.cc (locale::locale()): Likewise. + (locale::global(const locale&)): Likewise. + 2018-10-03 François Dumont <fdumont@gcc.gnu.org> * include/debug/map.h diff --git a/libstdc++-v3/src/c++98/locale.cc b/libstdc++-v3/src/c++98/locale.cc index 148bf59..fe06d29 100644 --- a/libstdc++-v3/src/c++98/locale.cc +++ b/libstdc++-v3/src/c++98/locale.cc @@ -77,7 +77,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION locale::locale(const locale& __other) throw() : _M_impl(__other._M_impl) - { _M_impl->_M_add_reference(); } + { + if (_M_impl != _S_classic) + _M_impl->_M_add_reference(); + } // This is used to initialize global and classic locales, and // assumes that the _Impl objects are constructed correctly. @@ -86,7 +89,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { } locale::~locale() throw() - { _M_impl->_M_remove_reference(); } + { + if (_M_impl != _S_classic) + _M_impl->_M_remove_reference(); + } bool locale::operator==(const locale& __rhs) const throw() @@ -112,8 +118,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const locale& locale::operator=(const locale& __other) throw() { - __other._M_impl->_M_add_reference(); - _M_impl->_M_remove_reference(); + if (__other._M_impl != _S_classic) + __other._M_impl->_M_add_reference(); + if (_M_impl != _S_classic) + _M_impl->_M_remove_reference(); _M_impl = __other._M_impl; return *this; } diff --git a/libstdc++-v3/src/c++98/locale_init.cc b/libstdc++-v3/src/c++98/locale_init.cc index c9078c0..b580a9f 100644 --- a/libstdc++-v3/src/c++98/locale_init.cc +++ b/libstdc++-v3/src/c++98/locale_init.cc @@ -257,9 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // fall back to lock protected access to both _S_global and // its reference count. _M_impl = _S_global; - if (_M_impl == _S_classic) - _M_impl->_M_add_reference(); - else + if (_M_impl != _S_classic) { __gnu_cxx::__scoped_lock sentry(get_locale_mutex()); _S_global->_M_add_reference(); @@ -275,7 +273,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __gnu_cxx::__scoped_lock sentry(get_locale_mutex()); __old = _S_global; - __other._M_impl->_M_add_reference(); + if (__other._M_impl != _S_classic) + __other._M_impl->_M_add_reference(); _S_global = __other._M_impl; const string __other_name = __other.name(); if (__other_name != "*") @@ -284,7 +283,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Reference count sanity check: one reference removed for the // subsition of __other locale, one added by return-by-value. Net - // difference: zero. When the returned locale object's destrutor + // difference: zero. When the returned locale object's destructor // is called, then the reference count is decremented and possibly // destroyed. return locale(__old); |