[PATCH] Threadsafe locale initialization
Pétur Runólfsson
peturr02@ru.is
Tue Sep 30 12:45:00 GMT 2003
Hi,
This patch attempts to make locale initialization threadsafe, by
using static initialization when possible (locale::facet::_S_c_name)
and initializing other members through __gthread_once
(locale::_S_classic and locale::facet::_S_c_locale). Also, statics
that are initialized statically (locale::_S_categories,
locale::facet::_S_c_name) are declared const.
This is needed so that locale can be initialized at any time during
program execution, and so that facets can be constructed before
locale::classic() is called. This means that locale no longer
depends on iostreams being initialized at the beginning of the
program.
Note that locale::global() and locale::locale() are still
thread-unsafe.
Tested on i686-pc-linux-gnu.
Petur
2003-09-30 Petur Runolfsson <peturr02@ru.is>
* config/locale/generic/c_locale.cc
(category_names, locale::_S_categories): Const qualify.
* config/locale/gnu/c_locale.cc: Same.
* config/locale/generic/time_members.h (__timepunct::__timepunct):
Copy string contents before assigning to _M_name_timepunct,
qualify strcpy and strlen with std::.
* config/locale/gnu/time_members.h: Same.
* config/locale/gnu/messages_members.h (messages::messages):
Copy string contents before assigning to _M_name_messages,
qualify strcpy and strlen with std::.
* config/os/gnu-linux/ctype_noninline.h
(ctype<char>::classic_table()): Don't call locale::classic().
* include/bits/locale_classes.h
(locale::_S_categories): Const qualify.
(locale::_S_once_mt, locale::_S_init, locale::facet::_S_once_mt,
locale::facet::_S_initialized, locale::facet::_S_init,
locale::facet::_S_get_c_locale): Declare.
(locale::_S_initialize): Don't define.
(locale::facet::_S_c_locale): Make private.
(locale::facet::_S_c_name): Const qualify.
(locale::_Impl::_Impl(facet**, size_t, bool)): Drop unused
parameters, add throw() specifier.
* include/bits/locale_facets.h (__timepunct::_M_name_timepunct,
messages::_M_name_messages): Const qualify.
* src/locale.cc
(locale::_S_once_mt, locale::facet::_S_once_mt,
locale::facet::_S_initialized): Define.
(locale::classic): Move initialization code...
(locale::_S_init): ...here.
(locale::_S_initialize): Call _S_init through __gthread_once.
(locale::facet::_S_init): Initialize _S_c_locale.
(locale::facet::_S_get_c_locale): Call _S_init through
__gthread_once before returning _S_c_locale.
* src/localename.cc (locale::_Impl::_Impl(facet**, size_t, bool)):
Drop unused parameters, add throw() specifier, don't initialize
locale::facet::_S_c_locale and _S_c_name.
* config/locale/generic/messages_members.h:
Replace _S_c_locale with _S_get_c_locale().
* config/locale/gnu/c_locale.cc: Same.
* config/locale/gnu/messages_members.h: Same.
* config/locale/gnu/numeric_members.cc: Same.
* config/locale/gnu/time_members.cc: Same.
* config/os/gnu-linux/ctype_noninline.h: Same.
* include/bits/locale_facets.h: Same.
* include/bits/locale_facets.tcc: Same.
* src/codecvt.cc: Same.
* src/ctype.cc: Same.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: locale-init.diff
Type: application/octet-stream
Size: 26522 bytes
Desc: locale-init.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20030930/7c8164e9/attachment.obj>
More information about the Gcc-patches
mailing list