// Definitions for static const data members of locale::id
_Atomic_word locale::id::_S_refcount; // init'd to 0 by linker
+ // XXX GLIBCXX_ABI Deprecated
+#ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
+namespace {
+ inline locale::id*
+ find_ldbl_sync_facet(locale::id* __idp)
+ {
+# define _GLIBCXX_SYNC_ID(facet, mangled) \
+ if (__idp == &::mangled) \
+ return &facet::id
+
+ _GLIBCXX_SYNC_ID (num_get<char>, _ZNSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
+ _GLIBCXX_SYNC_ID (num_put<char>, _ZNSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
+ _GLIBCXX_SYNC_ID (money_get<char>, _ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
+ _GLIBCXX_SYNC_ID (money_put<char>, _ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
+# ifdef _GLIBCXX_USE_WCHAR_T
+ _GLIBCXX_SYNC_ID (num_get<wchar_t>, _ZNSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
+ _GLIBCXX_SYNC_ID (num_put<wchar_t>, _ZNSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
+ _GLIBCXX_SYNC_ID (money_get<wchar_t>, _ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
+ _GLIBCXX_SYNC_ID (money_put<wchar_t>, _ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
+# endif
+ }
+} // namespace
+#endif
+
size_t
locale::id::_M_id() const throw()
{
{
// XXX GLIBCXX_ABI Deprecated
#ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
- locale::id *f = 0;
-# define _GLIBCXX_SYNC_ID(facet, mangled) \
- if (this == &::mangled) \
- f = &facet::id
- _GLIBCXX_SYNC_ID (num_get<char>, _ZNSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
- _GLIBCXX_SYNC_ID (num_put<char>, _ZNSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
- _GLIBCXX_SYNC_ID (money_get<char>, _ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
- _GLIBCXX_SYNC_ID (money_put<char>, _ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
-# ifdef _GLIBCXX_USE_WCHAR_T
- _GLIBCXX_SYNC_ID (num_get<wchar_t>, _ZNSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
- _GLIBCXX_SYNC_ID (num_put<wchar_t>, _ZNSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
- _GLIBCXX_SYNC_ID (money_get<wchar_t>, _ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
- _GLIBCXX_SYNC_ID (money_put<wchar_t>, _ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
-# endif
- if (f)
- _M_index = 1 + f->_M_id();
+ if (locale::id* f = find_ldbl_sync_facet(this))
+ {
+ const size_t sync_id = f->_M_id();
+ _M_index = 1 + sync_id;
+ return sync_id;
+ }
+#endif
+
+#ifdef __GTHREADS
+ if (__gthread_active_p())
+ {
+ if (__atomic_always_lock_free(sizeof(_M_index), &_M_index))
+ {
+ const _Atomic_word next
+ = 1 + __gnu_cxx::__exchange_and_add(&_S_refcount, 1);
+ size_t expected = 0;
+ __atomic_compare_exchange_n(&_M_index, &expected, next,
+ /* weak = */ false,
+ /* success = */ __ATOMIC_ACQ_REL,
+ /* failure = */ __ATOMIC_ACQUIRE);
+ }
+ else
+ {
+ static __gnu_cxx::__mutex m;
+ __gnu_cxx::__scoped_lock l(m);
+ if (!_M_index)
+ _M_index = ++_S_refcount;
+ }
+ }
else
#endif
- _M_index = 1 + __gnu_cxx::__exchange_and_add_dispatch(&_S_refcount,
- 1);
+ _M_index = ++_S_refcount; // single-threaded case
}
return _M_index - 1;
}