|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75463 - in trunk/boost/chrono/io: . utility
From: vicente.botet_at_[hidden]
Date: 2011-11-12 12:46:04
Author: viboes
Date: 2011-11-12 12:46:03 EST (Sat, 12 Nov 2011)
New Revision: 75463
URL: http://svn.boost.org/trac/boost/changeset/75463
Log:
Chrono: Ensure that the ios index are intermodule and thread safe.
Text files modified:
trunk/boost/chrono/io/ios_base_state.hpp | 18 ++++++++++++++++++
trunk/boost/chrono/io/utility/ios_base_state_ptr.hpp | 36 ++++++++++++++++++++++++++++++++----
2 files changed, 50 insertions(+), 4 deletions(-)
Modified: trunk/boost/chrono/io/ios_base_state.hpp
==============================================================================
--- trunk/boost/chrono/io/ios_base_state.hpp (original)
+++ trunk/boost/chrono/io/ios_base_state.hpp 2011-11-12 12:46:03 EST (Sat, 12 Nov 2011)
@@ -59,6 +59,13 @@
}
};
+ namespace detail
+ {
+ namespace /**/ {
+ xalloc_key_initializer_t<ios_base_flags<fmt_masks> > fmt_masks_xalloc_key_initializer;
+ } // namespace
+ } // namespace detail
+
inline duration_style::type get_duration_style(std::ios_base & ios)
{
return fmt_masks(ios).get_duration_style();
@@ -95,6 +102,17 @@
};
} // detail
+ namespace detail
+ {
+ namespace /**/ {
+ xalloc_key_initializer_t<ios_base_state<detail::ios_base_data_aux<char> > > ios_base_data_aux_xalloc_key_initializer;
+ xalloc_key_initializer_t<ios_base_state<detail::ios_base_data_aux<wchar_t> > > wios_base_data_aux_xalloc_key_initializer;
+#if BOOST_CHRONO_HAS_UNICODE_SUPPORT
+ xalloc_key_initializer_t<ios_base_state<detail::ios_base_data_aux<char16_t> > > c16_ios_base_data_aux_xalloc_key_initializer;
+ xalloc_key_initializer_t<ios_base_state<detail::ios_base_data_aux<char32_t> > > ios_base_data_aux_xalloc_key_initializer;
+#endif
+ } // namespace
+ } // namespace detail
template<typename CharT>
static inline std::basic_string<CharT> get_time_fmt(std::ios_base & ios)
Modified: trunk/boost/chrono/io/utility/ios_base_state_ptr.hpp
==============================================================================
--- trunk/boost/chrono/io/utility/ios_base_state_ptr.hpp (original)
+++ trunk/boost/chrono/io/utility/ios_base_state_ptr.hpp 2011-11-12 12:46:03 EST (Sat, 12 Nov 2011)
@@ -23,6 +23,36 @@
{
namespace chrono
{
+ namespace detail
+ {
+
+ template<typename T>
+ struct xalloc_key_holder
+ {
+ static int value;
+ static bool initialized;
+ };
+
+ template<typename T>
+ int xalloc_key_holder<T>::value = 0;
+
+ template<typename T>
+ bool xalloc_key_holder<T>::initialized = false;
+
+ template<typename T>
+ struct xalloc_key_initializer_t
+ {
+ xalloc_key_initializer_t()
+ {
+ if (!xalloc_key_holder<T>::initialized)
+ {
+ xalloc_key_holder<T>::value = std::ios_base::xalloc();
+ xalloc_key_holder<T>::initialized = true;
+ }
+ }
+ };
+ }
+
/**
* @c ios_base_state_ptr is a smart pointer to a ios_base specific state.
@@ -192,8 +222,7 @@
static inline int index()
{
- static const int v_ = std::ios_base::xalloc();
- return v_;
+ return detail::xalloc_key_holder<ios_base_state_ptr<T> >::value;
}
static inline void register_once(int indx, std::ios_base& ios)
@@ -310,8 +339,7 @@
}
static inline int index()
{
- static const int v_ = std::ios_base::xalloc();
- return v_;
+ return detail::xalloc_key_holder<ios_base_flags<Base> >::value;
}
std::ios_base& ios_;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk