libstdc++: Partially revert r11-5314
authorJonathan Wakely <jwakely@redhat.com>
Fri, 27 Nov 2020 11:00:15 +0000 (11:00 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 27 Nov 2020 12:25:02 +0000 (12:25 +0000)
The changes in r11-5314 are broken, because it means we don't use
__gthread_once for the first few initializations, but after the program
becomes multi-threaded we will repeat the initialization, using
__gthread_once once this time. This leads to memory errors.

The use of __is_single_threaded() in locale::id::_M_id() is OK, because
the side effects are the same either way.

libstdc++-v3/ChangeLog:

* src/c++98/locale.cc (locale::facet::_S_get_c_locale()):
Revert change to use __is_single_threaded.
* src/c++98/locale_init.cc (locale::_S_initialize()):
Likewise.

libstdc++-v3/src/c++98/locale.cc
libstdc++-v3/src/c++98/locale_init.cc

index 9b3fc3515152318ba99783e433132f12d4ac5956..4c1612cc5dca3bdb3f424d300bb6cb23a0a2b58a 100644 (file)
@@ -214,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   locale::facet::_S_get_c_locale()
   {
 #ifdef __GTHREADS
-    if (!__gnu_cxx::__is_single_threaded())
+    if (__gthread_active_p())
       __gthread_once(&_S_once, _S_initialize_once);
     else
 #endif
index fc8416ba01a62377718b7a3004973b909fba307b..c3841ccbd3c96b4b0c28d0498250a8e8545c0c3b 100644 (file)
@@ -320,7 +320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   locale::_S_initialize()
   {
 #ifdef __GTHREADS
-    if (!__gnu_cxx::__is_single_threaded())
+    if (__gthread_active_p())
       __gthread_once(&_S_once, _S_initialize_once);
 #endif
     if (!_S_classic)