]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 1997-2022 Free Software Foundation, Inc. |
b2dad0e3 BK |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
b2dad0e3 BK |
7 | // any later version. |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
748086b7 JJ |
14 | // Under Section 7 of GPL version 3, you are granted additional |
15 | // permissions described in the GCC Runtime Library Exception, version | |
16 | // 3.1, as published by the Free Software Foundation. | |
b2dad0e3 | 17 | |
748086b7 JJ |
18 | // You should have received a copy of the GNU General Public License and |
19 | // a copy of the GCC Runtime Library Exception along with this program; | |
20 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
21 | // <http://www.gnu.org/licenses/>. | |
b2dad0e3 | 22 | |
34a2b755 | 23 | #define _GLIBCXX_USE_CXX11_ABI 1 |
54c1bf78 BK |
24 | #include <clocale> |
25 | #include <cstring> | |
54c1bf78 | 26 | #include <cctype> |
d3a193e3 | 27 | #include <cwctype> // For towupper, etc. |
54c1bf78 | 28 | #include <locale> |
2e362c74 | 29 | #include <ext/concurrence.h> |
18c75543 | 30 | |
b82f782b | 31 | namespace |
18c75543 | 32 | { |
99827523 BK |
33 | __gnu_cxx::__mutex& |
34 | get_locale_cache_mutex() | |
35 | { | |
36 | static __gnu_cxx::__mutex locale_cache_mutex; | |
37 | return locale_cache_mutex; | |
38 | } | |
2e362c74 | 39 | } // anonymous namespace |
17325050 | 40 | |
6defecc2 JJ |
41 | // XXX GLIBCXX_ABI Deprecated |
42 | #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT | |
43 | # define _GLIBCXX_LOC_ID(mangled) extern std::locale::id mangled | |
44 | _GLIBCXX_LOC_ID (_ZNSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE); | |
45 | _GLIBCXX_LOC_ID (_ZNSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE); | |
46 | _GLIBCXX_LOC_ID (_ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE); | |
47 | _GLIBCXX_LOC_ID (_ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE); | |
48 | # ifdef _GLIBCXX_USE_WCHAR_T | |
49 | _GLIBCXX_LOC_ID (_ZNSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE); | |
50 | _GLIBCXX_LOC_ID (_ZNSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE); | |
51 | _GLIBCXX_LOC_ID (_ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE); | |
52 | _GLIBCXX_LOC_ID (_ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE); | |
53 | # endif | |
54 | #endif | |
55 | ||
12ffa228 BK |
56 | namespace std _GLIBCXX_VISIBILITY(default) |
57 | { | |
58 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
3cbc7af0 | 59 | |
0479a462 | 60 | // Definitions for static const data members of locale. |
b75bedeb | 61 | const locale::category locale::none; |
b75bedeb | 62 | const locale::category locale::ctype; |
b75bedeb | 63 | const locale::category locale::numeric; |
0a31609b | 64 | const locale::category locale::collate; |
b75bedeb | 65 | const locale::category locale::time; |
0a31609b | 66 | const locale::category locale::monetary; |
b75bedeb BK |
67 | const locale::category locale::messages; |
68 | const locale::category locale::all; | |
69 | ||
8099b2ae | 70 | // These are no longer exported. |
8ae81136 | 71 | locale::_Impl* locale::_S_classic; |
f92ab29f | 72 | locale::_Impl* locale::_S_global; |
0479a462 | 73 | |
8ae81136 BK |
74 | #ifdef __GTHREADS |
75 | __gthread_once_t locale::_S_once = __GTHREAD_ONCE_INIT; | |
76 | #endif | |
77 | ||
0214010c | 78 | locale::locale(const locale& __other) throw() |
26c691a8 | 79 | : _M_impl(__other._M_impl) |
749c0e1d JW |
80 | { |
81 | if (_M_impl != _S_classic) | |
82 | _M_impl->_M_add_reference(); | |
83 | } | |
0214010c | 84 | |
1f46fc8e BK |
85 | // This is used to initialize global and classic locales, and |
86 | // assumes that the _Impl objects are constructed correctly. | |
402a402c | 87 | // The lack of a reference increment is intentional. |
1f46fc8e BK |
88 | locale::locale(_Impl* __ip) throw() : _M_impl(__ip) |
89 | { } | |
0214010c | 90 | |
402a402c | 91 | locale::~locale() throw() |
749c0e1d JW |
92 | { |
93 | if (_M_impl != _S_classic) | |
94 | _M_impl->_M_remove_reference(); | |
95 | } | |
402a402c | 96 | |
0214010c BK |
97 | bool |
98 | locale::operator==(const locale& __rhs) const throw() | |
99 | { | |
4df9c41d PC |
100 | // Deal first with the common cases, fast to process: refcopies, |
101 | // unnamed (i.e., !_M_names[0]), "simple" (!_M_names[1] => all the | |
102 | // categories same name, i.e., _M_names[0]). Otherwise fall back | |
103 | // to the general locale::name(). | |
104 | bool __ret; | |
d7ed521b | 105 | if (_M_impl == __rhs._M_impl) |
4df9c41d PC |
106 | __ret = true; |
107 | else if (!_M_impl->_M_names[0] || !__rhs._M_impl->_M_names[0] | |
108 | || std::strcmp(_M_impl->_M_names[0], | |
109 | __rhs._M_impl->_M_names[0]) != 0) | |
59639106 | 110 | __ret = false; |
4df9c41d PC |
111 | else if (!_M_impl->_M_names[1] && !__rhs._M_impl->_M_names[1]) |
112 | __ret = true; | |
d7ed521b | 113 | else |
4df9c41d | 114 | __ret = this->name() == __rhs.name(); |
d7ed521b | 115 | return __ret; |
0214010c BK |
116 | } |
117 | ||
118 | const locale& | |
119 | locale::operator=(const locale& __other) throw() | |
120 | { | |
749c0e1d JW |
121 | if (__other._M_impl != _S_classic) |
122 | __other._M_impl->_M_add_reference(); | |
123 | if (_M_impl != _S_classic) | |
124 | _M_impl->_M_remove_reference(); | |
0214010c BK |
125 | _M_impl = __other._M_impl; |
126 | return *this; | |
127 | } | |
128 | ||
34a2b755 | 129 | _GLIBCXX_DEFAULT_ABI_TAG |
0214010c BK |
130 | string |
131 | locale::name() const | |
132 | { | |
d3a193e3 | 133 | string __ret; |
4df9c41d PC |
134 | if (!_M_impl->_M_names[0]) |
135 | __ret = '*'; | |
136 | else if (_M_impl->_M_check_same_name()) | |
0214010c BK |
137 | __ret = _M_impl->_M_names[0]; |
138 | else | |
139 | { | |
4df9c41d | 140 | __ret.reserve(128); |
aa53f832 | 141 | __ret += _S_categories[0]; |
f815521c | 142 | __ret += '='; |
f92ab29f | 143 | __ret += _M_impl->_M_names[0]; |
73c4dcc6 | 144 | for (size_t __i = 1; __i < _S_categories_size; ++__i) |
d3a193e3 | 145 | { |
f815521c | 146 | __ret += ';'; |
aa53f832 | 147 | __ret += _S_categories[__i]; |
f815521c | 148 | __ret += '='; |
aa53f832 | 149 | __ret += _M_impl->_M_names[__i]; |
d3a193e3 | 150 | } |
0214010c BK |
151 | } |
152 | return __ret; | |
153 | } | |
154 | ||
0214010c | 155 | locale::category |
f92ab29f | 156 | locale::_S_normalize_category(category __cat) |
0214010c | 157 | { |
758c46c9 | 158 | int __ret = 0; |
2a67bec2 | 159 | if (__cat == none || ((__cat & all) && !(__cat & ~all))) |
0214010c BK |
160 | __ret = __cat; |
161 | else | |
162 | { | |
163 | // NB: May be a C-style "LC_ALL" category; convert. | |
164 | switch (__cat) | |
165 | { | |
f92ab29f CG |
166 | case LC_COLLATE: |
167 | __ret = collate; | |
0214010c | 168 | break; |
f92ab29f | 169 | case LC_CTYPE: |
0214010c BK |
170 | __ret = ctype; |
171 | break; | |
f92ab29f | 172 | case LC_MONETARY: |
0214010c BK |
173 | __ret = monetary; |
174 | break; | |
f92ab29f | 175 | case LC_NUMERIC: |
0214010c BK |
176 | __ret = numeric; |
177 | break; | |
f92ab29f CG |
178 | case LC_TIME: |
179 | __ret = time; | |
0214010c | 180 | break; |
3d7c150e | 181 | #ifdef _GLIBCXX_HAVE_LC_MESSAGES |
f92ab29f | 182 | case LC_MESSAGES: |
0214010c BK |
183 | __ret = messages; |
184 | break; | |
f92ab29f CG |
185 | #endif |
186 | case LC_ALL: | |
0214010c BK |
187 | __ret = all; |
188 | break; | |
189 | default: | |
ba9119ec PC |
190 | __throw_runtime_error(__N("locale::_S_normalize_category " |
191 | "category not found")); | |
0214010c BK |
192 | } |
193 | } | |
194 | return __ret; | |
195 | } | |
196 | ||
c755e77d | 197 | // locale::facet |
8ae81136 BK |
198 | __c_locale locale::facet::_S_c_locale; |
199 | ||
200 | const char locale::facet::_S_c_name[2] = "C"; | |
201 | ||
202 | #ifdef __GTHREADS | |
203 | __gthread_once_t locale::facet::_S_once = __GTHREAD_ONCE_INIT; | |
204 | #endif | |
1c26d8fd | 205 | |
8ae81136 BK |
206 | void |
207 | locale::facet::_S_initialize_once() | |
208 | { | |
209 | // Initialize the underlying locale model. | |
210 | _S_create_c_locale(_S_c_locale, _S_c_name); | |
211 | } | |
212 | ||
213 | __c_locale | |
214 | locale::facet::_S_get_c_locale() | |
215 | { | |
b87bc3aa | 216 | #ifdef __GTHREADS |
0d7d69ca | 217 | if (__gthread_active_p()) |
5c109a17 BK |
218 | __gthread_once(&_S_once, _S_initialize_once); |
219 | else | |
8ae81136 | 220 | #endif |
5c109a17 BK |
221 | { |
222 | if (!_S_c_locale) | |
223 | _S_initialize_once(); | |
224 | } | |
8ae81136 BK |
225 | return _S_c_locale; |
226 | } | |
227 | ||
bb1b12ec | 228 | const char* |
32ade559 | 229 | locale::facet::_S_get_c_name() throw() |
bb1b12ec BK |
230 | { return _S_c_name; } |
231 | ||
c755e77d BK |
232 | locale::facet:: |
233 | ~facet() { } | |
bf3b866e | 234 | |
c755e77d BK |
235 | // locale::_Impl |
236 | locale::_Impl:: | |
237 | ~_Impl() throw() | |
238 | { | |
239 | if (_M_facets) | |
240 | for (size_t __i = 0; __i < _M_facets_size; ++__i) | |
241 | if (_M_facets[__i]) | |
242 | _M_facets[__i]->_M_remove_reference(); | |
243 | delete [] _M_facets; | |
244 | ||
245 | if (_M_caches) | |
246 | for (size_t __i = 0; __i < _M_facets_size; ++__i) | |
247 | if (_M_caches[__i]) | |
f92ab29f | 248 | _M_caches[__i]->_M_remove_reference(); |
c755e77d BK |
249 | delete [] _M_caches; |
250 | ||
251 | if (_M_names) | |
252 | for (size_t __i = 0; __i < _S_categories_size; ++__i) | |
f92ab29f | 253 | delete [] _M_names[__i]; |
c755e77d BK |
254 | delete [] _M_names; |
255 | } | |
bf3b866e | 256 | |
c755e77d BK |
257 | // Clone existing _Impl object. |
258 | locale::_Impl:: | |
259 | _Impl(const _Impl& __imp, size_t __refs) | |
26c691a8 BK |
260 | : _M_refcount(__refs), _M_facets(0), _M_facets_size(__imp._M_facets_size), |
261 | _M_caches(0), _M_names(0) | |
c755e77d | 262 | { |
bc2631e0 | 263 | __try |
c755e77d BK |
264 | { |
265 | _M_facets = new const facet*[_M_facets_size]; | |
266 | for (size_t __i = 0; __i < _M_facets_size; ++__i) | |
267 | { | |
268 | _M_facets[__i] = __imp._M_facets[__i]; | |
269 | if (_M_facets[__i]) | |
270 | _M_facets[__i]->_M_add_reference(); | |
271 | } | |
272 | _M_caches = new const facet*[_M_facets_size]; | |
95b147fe | 273 | for (size_t __j = 0; __j < _M_facets_size; ++__j) |
c755e77d | 274 | { |
95b147fe SM |
275 | _M_caches[__j] = __imp._M_caches[__j]; |
276 | if (_M_caches[__j]) | |
f92ab29f | 277 | _M_caches[__j]->_M_add_reference(); |
c755e77d BK |
278 | } |
279 | _M_names = new char*[_S_categories_size]; | |
95b147fe SM |
280 | for (size_t __k = 0; __k < _S_categories_size; ++__k) |
281 | _M_names[__k] = 0; | |
c755e77d | 282 | |
4df9c41d | 283 | // Name the categories. |
95b147fe SM |
284 | for (size_t __l = 0; (__l < _S_categories_size |
285 | && __imp._M_names[__l]); ++__l) | |
c755e77d | 286 | { |
95b147fe SM |
287 | const size_t __len = std::strlen(__imp._M_names[__l]) + 1; |
288 | _M_names[__l] = new char[__len]; | |
289 | std::memcpy(_M_names[__l], __imp._M_names[__l], __len); | |
c755e77d BK |
290 | } |
291 | } | |
bc2631e0 | 292 | __catch(...) |
c755e77d BK |
293 | { |
294 | this->~_Impl(); | |
295 | __throw_exception_again; | |
296 | } | |
297 | } | |
bf3b866e | 298 | |
5dc91152 | 299 | void |
c755e77d | 300 | locale::_Impl:: |
f92ab29f | 301 | _M_replace_category(const _Impl* __imp, |
95b147fe | 302 | const locale::id* const* __idpp) |
bf3b866e | 303 | { |
c755e77d BK |
304 | for (; *__idpp; ++__idpp) |
305 | _M_replace_facet(__imp, *__idpp); | |
306 | } | |
f92ab29f | 307 | |
c755e77d BK |
308 | void |
309 | locale::_Impl:: | |
310 | _M_replace_facet(const _Impl* __imp, const locale::id* __idp) | |
311 | { | |
312 | size_t __index = __idp->_M_id(); | |
f92ab29f | 313 | if ((__index > (__imp->_M_facets_size - 1)) |
95b147fe | 314 | || !__imp->_M_facets[__index]) |
ba9119ec | 315 | __throw_runtime_error(__N("locale::_Impl::_M_replace_facet")); |
f92ab29f | 316 | _M_install_facet(__idp, __imp->_M_facets[__index]); |
c755e77d BK |
317 | } |
318 | ||
319 | void | |
320 | locale::_Impl:: | |
321 | _M_install_facet(const locale::id* __idp, const facet* __fp) | |
322 | { | |
323 | if (__fp) | |
324 | { | |
325 | size_t __index = __idp->_M_id(); | |
326 | ||
327 | // Check size of facet vector to ensure adequate room. | |
328 | if (__index > _M_facets_size - 1) | |
329 | { | |
330 | const size_t __new_size = __index + 4; | |
331 | ||
332 | // New facet array. | |
333 | const facet** __oldf = _M_facets; | |
334 | const facet** __newf; | |
f92ab29f | 335 | __newf = new const facet*[__new_size]; |
c755e77d BK |
336 | for (size_t __i = 0; __i < _M_facets_size; ++__i) |
337 | __newf[__i] = _M_facets[__i]; | |
95b147fe SM |
338 | for (size_t __l = _M_facets_size; __l < __new_size; ++__l) |
339 | __newf[__l] = 0; | |
c755e77d BK |
340 | |
341 | // New cache array. | |
342 | const facet** __oldc = _M_caches; | |
343 | const facet** __newc; | |
bc2631e0 | 344 | __try |
c755e77d BK |
345 | { |
346 | __newc = new const facet*[__new_size]; | |
347 | } | |
bc2631e0 | 348 | __catch(...) |
c755e77d BK |
349 | { |
350 | delete [] __newf; | |
351 | __throw_exception_again; | |
352 | } | |
95b147fe SM |
353 | for (size_t __j = 0; __j < _M_facets_size; ++__j) |
354 | __newc[__j] = _M_caches[__j]; | |
355 | for (size_t __k = _M_facets_size; __k < __new_size; ++__k) | |
356 | __newc[__k] = 0; | |
c755e77d BK |
357 | |
358 | _M_facets_size = __new_size; | |
359 | _M_facets = __newf; | |
360 | _M_caches = __newc; | |
361 | delete [] __oldf; | |
362 | delete [] __oldc; | |
363 | } | |
364 | ||
365 | __fp->_M_add_reference(); | |
366 | const facet*& __fpr = _M_facets[__index]; | |
367 | if (__fpr) | |
368 | { | |
34a2b755 JW |
369 | #if _GLIBCXX_USE_DUAL_ABI |
370 | // If this is a twinned facet replace its twin with a shim. | |
371 | for (const id* const* p = _S_twinned_facets; *p != 0; p += 2) | |
372 | { | |
373 | if (p[0]->_M_id() == __index) | |
374 | { | |
375 | // replacing the old ABI facet, also replace new ABI twin | |
376 | const facet*& __fpr2 = _M_facets[p[1]->_M_id()]; | |
377 | if (__fpr2) | |
378 | { | |
379 | const facet* __fp2 = __fp->_M_sso_shim(p[1]); | |
380 | __fp2->_M_add_reference(); | |
381 | __fpr2->_M_remove_reference(); | |
382 | __fpr2 = __fp2; | |
383 | } | |
384 | break; | |
385 | } | |
386 | else if (p[1]->_M_id() == __index) | |
387 | { | |
388 | // replacing the new ABI facet, also replace old ABI twin | |
389 | const facet*& __fpr2 = _M_facets[p[0]->_M_id()]; | |
390 | if (__fpr2) | |
391 | { | |
392 | const facet* __fp2 = __fp->_M_cow_shim(p[0]); | |
393 | __fp2->_M_add_reference(); | |
394 | __fpr2->_M_remove_reference(); | |
395 | __fpr2 = __fp2; | |
396 | } | |
397 | break; | |
398 | } | |
399 | } | |
400 | #endif | |
c755e77d BK |
401 | // Replacing an existing facet. Order matters. |
402 | __fpr->_M_remove_reference(); | |
403 | __fpr = __fp; | |
404 | } | |
405 | else | |
406 | { | |
407 | // Installing a newly created facet into an empty | |
408 | // _M_facets container, say a newly-constructed, | |
409 | // swanky-fresh _Impl. | |
410 | _M_facets[__index] = __fp; | |
411 | } | |
412 | ||
413 | // Ideally, it would be nice to only remove the caches that | |
414 | // are now incorrect. However, some of the caches depend on | |
415 | // multiple facets, and we only know about one facet | |
416 | // here. It's no great loss: the first use of the new facet | |
417 | // will create a new, correctly cached facet anyway. | |
418 | for (size_t __i = 0; __i < _M_facets_size; ++__i) | |
419 | { | |
420 | const facet* __cpr = _M_caches[__i]; | |
421 | if (__cpr) | |
422 | { | |
423 | __cpr->_M_remove_reference(); | |
424 | _M_caches[__i] = 0; | |
425 | } | |
426 | } | |
427 | } | |
428 | } | |
429 | ||
18c75543 ILT |
430 | void |
431 | locale::_Impl:: | |
432 | _M_install_cache(const facet* __cache, size_t __index) | |
433 | { | |
99827523 | 434 | __gnu_cxx::__scoped_lock sentry(get_locale_cache_mutex()); |
34a2b755 JW |
435 | #if _GLIBCXX_USE_DUAL_ABI |
436 | // If this cache is for one of the facets that is instantiated twice, | |
437 | // for old and new std::string ABI, install it in both slots. | |
438 | size_t __index2 = -1; | |
439 | for (const id* const* p = _S_twinned_facets; *p != 0; p += 2) | |
440 | { | |
441 | if (p[0]->_M_id() == __index) | |
442 | { | |
443 | __index2 = p[1]->_M_id(); | |
444 | break; | |
445 | } | |
446 | else if (p[1]->_M_id() == __index) | |
447 | { | |
448 | __index2 = __index; | |
449 | __index = p[0]->_M_id(); | |
450 | break; | |
451 | } | |
452 | } | |
453 | #endif | |
18c75543 ILT |
454 | if (_M_caches[__index] != 0) |
455 | { | |
456 | // Some other thread got in first. | |
457 | delete __cache; | |
458 | } | |
459 | else | |
460 | { | |
461 | __cache->_M_add_reference(); | |
462 | _M_caches[__index] = __cache; | |
34a2b755 JW |
463 | #if _GLIBCXX_USE_DUAL_ABI |
464 | if (__index2 != size_t(-1)) | |
465 | { | |
466 | __cache->_M_add_reference(); | |
467 | _M_caches[__index2] = __cache; | |
468 | } | |
469 | #endif | |
18c75543 ILT |
470 | } |
471 | } | |
472 | ||
c755e77d BK |
473 | // locale::id |
474 | // Definitions for static const data members of locale::id | |
1313d87f | 475 | _Atomic_word locale::id::_S_refcount; // init'd to 0 by linker |
c755e77d | 476 | |
cc386cf2 JW |
477 | // XXX GLIBCXX_ABI Deprecated |
478 | #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT | |
479 | namespace { | |
480 | inline locale::id* | |
9cfc400f | 481 | find_ldbl_sync_facet(const locale::id* __idp) |
cc386cf2 JW |
482 | { |
483 | # define _GLIBCXX_SYNC_ID(facet, mangled) \ | |
484 | if (__idp == &::mangled) \ | |
485 | return &facet::id | |
486 | ||
487 | _GLIBCXX_SYNC_ID (num_get<char>, _ZNSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE); | |
488 | _GLIBCXX_SYNC_ID (num_put<char>, _ZNSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE); | |
489 | _GLIBCXX_SYNC_ID (money_get<char>, _ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE); | |
490 | _GLIBCXX_SYNC_ID (money_put<char>, _ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE); | |
491 | # ifdef _GLIBCXX_USE_WCHAR_T | |
492 | _GLIBCXX_SYNC_ID (num_get<wchar_t>, _ZNSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE); | |
493 | _GLIBCXX_SYNC_ID (num_put<wchar_t>, _ZNSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE); | |
494 | _GLIBCXX_SYNC_ID (money_get<wchar_t>, _ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE); | |
495 | _GLIBCXX_SYNC_ID (money_put<wchar_t>, _ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE); | |
496 | # endif | |
9cfc400f | 497 | return 0; |
cc386cf2 JW |
498 | } |
499 | } // namespace | |
500 | #endif | |
501 | ||
c755e77d | 502 | size_t |
32ade559 | 503 | locale::id::_M_id() const throw() |
c755e77d BK |
504 | { |
505 | if (!_M_index) | |
6defecc2 JJ |
506 | { |
507 | // XXX GLIBCXX_ABI Deprecated | |
508 | #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT | |
cc386cf2 JW |
509 | if (locale::id* f = find_ldbl_sync_facet(this)) |
510 | { | |
511 | const size_t sync_id = f->_M_id(); | |
512 | _M_index = 1 + sync_id; | |
513 | return sync_id; | |
514 | } | |
515 | #endif | |
516 | ||
517 | #ifdef __GTHREADS | |
e253d362 | 518 | if (!__gnu_cxx::__is_single_threaded()) |
cc386cf2 JW |
519 | { |
520 | if (__atomic_always_lock_free(sizeof(_M_index), &_M_index)) | |
521 | { | |
522 | const _Atomic_word next | |
523 | = 1 + __gnu_cxx::__exchange_and_add(&_S_refcount, 1); | |
524 | size_t expected = 0; | |
525 | __atomic_compare_exchange_n(&_M_index, &expected, next, | |
526 | /* weak = */ false, | |
527 | /* success = */ __ATOMIC_ACQ_REL, | |
528 | /* failure = */ __ATOMIC_ACQUIRE); | |
529 | } | |
530 | else | |
531 | { | |
532 | static __gnu_cxx::__mutex m; | |
533 | __gnu_cxx::__scoped_lock l(m); | |
534 | if (!_M_index) | |
535 | _M_index = ++_S_refcount; | |
536 | } | |
537 | } | |
6defecc2 JJ |
538 | else |
539 | #endif | |
cc386cf2 | 540 | _M_index = ++_S_refcount; // single-threaded case |
6defecc2 | 541 | } |
c755e77d | 542 | return _M_index - 1; |
bf3b866e | 543 | } |
3cbc7af0 | 544 | |
12ffa228 BK |
545 | _GLIBCXX_END_NAMESPACE_VERSION |
546 | } // namespace |