|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r49311 - branches/release/boost/serialization
From: ramey_at_[hidden]
Date: 2008-10-13 00:02:58
Author: ramey
Date: 2008-10-13 00:02:58 EDT (Mon, 13 Oct 2008)
New Revision: 49311
URL: http://svn.boost.org/trac/boost/changeset/49311
Log:
Tested fix for gcc crash on static object destruction
Text files modified:
branches/release/boost/serialization/singleton.hpp | 32 +++++++++++++++++++++-----------
1 files changed, 21 insertions(+), 11 deletions(-)
Modified: branches/release/boost/serialization/singleton.hpp
==============================================================================
--- branches/release/boost/serialization/singleton.hpp (original)
+++ branches/release/boost/serialization/singleton.hpp 2008-10-13 00:02:58 EDT (Mon, 13 Oct 2008)
@@ -93,21 +93,37 @@
}
};
+namespace detail {
+
+template<class T>
+class singleton_wrapper : public T
+{
+public:
+ static bool m_is_destroyed;
+ ~singleton_wrapper(){
+ m_is_destroyed = true;
+ }
+};
+
+template<class T>
+bool detail::singleton_wrapper<T>::m_is_destroyed = false;
+
+} // detail
+
template <class T>
class singleton : public singleton_module
{
private:
- static bool m_is_destroyed;
BOOST_DLLEXPORT static T & instance;
// include this to provoke instantiation at pre-execution time
static void use(T const &) {}
BOOST_DLLEXPORT static T & get_instance() {
- static T t;
+ static detail::singleton_wrapper<T> t;
// refer to instance, causing it to be instantiated (and
// initialized at startup on working compilers)
- assert(! m_is_destroyed);
+ assert(! detail::singleton_wrapper<T>::m_is_destroyed);
use(instance);
- return t;
+ return static_cast<T &>(t);
}
public:
BOOST_DLLEXPORT static T & get_mutable_instance(){
@@ -118,19 +134,13 @@
return get_instance();
}
BOOST_DLLEXPORT static bool is_destroyed(){
- return m_is_destroyed;
- }
- ~singleton(){
- m_is_destroyed = true;
+ return detail::singleton_wrapper<T>::m_is_destroyed;
}
};
template<class T>
BOOST_DLLEXPORT T & singleton<T>::instance = singleton<T>::get_instance();
-template<class T>
-bool singleton<T>::m_is_destroyed = false;
-
} // namespace serialization
} // namespace boost
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