From b0a794da38b52c8ae0f8155cf3bb30321cf67f00 Mon Sep 17 00:00:00 2001 From: Robert Ramey Date: Thu, 23 Feb 2017 13:25:27 -0800 Subject: [PATCH] Trying to get minGW to function for serialization library simplify singleton.hpp and singleton.cpp alter appveyor.yml --- appveyor.yml | 3 +- .../archive/impl/archive_serializer_map.ipp | 4 ++ include/boost/serialization/singleton.hpp | 56 +++++++++---------- src/extended_type_info.cpp | 1 + src/extended_type_info_typeid.cpp | 1 + src/singleton.cpp | 12 ---- src/void_cast.cpp | 1 + 7 files changed, 36 insertions(+), 42 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 39c92087..39b27181 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -56,9 +56,8 @@ install: - git submodule init tools/build - git submodule update - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\serialization - - set PATH=C:\MinGW\bin;%PATH% + - set PATH=C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1;%PATH% - bootstrap mingw - - type bootstrap.log - tools\build\v2\b2 headers build: off diff --git a/include/boost/archive/impl/archive_serializer_map.ipp b/include/boost/archive/impl/archive_serializer_map.ipp index 8dabf0d0..7f163ec4 100644 --- a/include/boost/archive/impl/archive_serializer_map.ipp +++ b/include/boost/archive/impl/archive_serializer_map.ipp @@ -47,6 +47,10 @@ archive_serializer_map::insert(const basic_serializer * bs){ template BOOST_ARCHIVE_OR_WARCHIVE_DECL void archive_serializer_map::erase(const basic_serializer * bs){ + BOOST_ASSERT(! boost::serialization::singleton< + extra_detail::map + >::is_destroyed() + ); if(boost::serialization::singleton< extra_detail::map >::is_destroyed()) diff --git a/include/boost/serialization/singleton.hpp b/include/boost/serialization/singleton.hpp index a40488c6..0df50661 100644 --- a/include/boost/serialization/singleton.hpp +++ b/include/boost/serialization/singleton.hpp @@ -90,35 +90,14 @@ public: static void lock(){ get_lock() = true; } - static void unlock(){ get_lock() = false; } - static bool is_locked(){ return get_lock(); } }; -#include // pops abi_suffix.hpp pragmas - -namespace detail { - -template -class singleton_wrapper : public T -{ -public: - static bool m_is_destroyed; - ~singleton_wrapper(){ - m_is_destroyed = true; - } -}; - -template -bool detail::singleton_wrapper< T >::m_is_destroyed = false; - -} // detail - // note usage of BOOST_DLLEXPORT. These functions are in danger of // being eliminated by the optimizer when building an application in // release mode. Usage of the macro is meant to signal the compiler/linker @@ -129,17 +108,30 @@ template class singleton : public singleton_module { private: - BOOST_DLLEXPORT static T & instance; + static T & m_instance; // include this to provoke instantiation at pre-execution time static void use(T const *) {} - BOOST_DLLEXPORT static T & get_instance() { - static detail::singleton_wrapper< T > t; + static T & get_instance() { + // use a wrapper so that types T with protected constructors + // can be used + class singleton_wrapper : public T {}; + static singleton_wrapper t; // refer to instance, causing it to be instantiated (and // initialized at startup on working compilers) - BOOST_ASSERT(! detail::singleton_wrapper< T >::m_is_destroyed); - use(& instance); + BOOST_ASSERT(! is_destroyed()); + // note that the following is absolutely essential. + // commenting out this statement will cause compilers to fail to + // construct the instance at pre-execution time. This would prevent + // our usage/implementation of "locking" and introduce uncertainty into + // the sequence of object initializaition. + use(& m_instance); return static_cast(t); } + static bool & get_is_destroyed(){ + static bool is_destroyed; + return is_destroyed; + } + public: BOOST_DLLEXPORT static T & get_mutable_instance(){ BOOST_ASSERT(! is_locked()); @@ -149,16 +141,24 @@ public: return get_instance(); } BOOST_DLLEXPORT static bool is_destroyed(){ - return detail::singleton_wrapper< T >::m_is_destroyed; + return get_is_destroyed(); + } + BOOST_DLLEXPORT singleton(){ + get_is_destroyed() = false; + } + BOOST_DLLEXPORT ~singleton() { + get_is_destroyed() = true; } }; template -BOOST_DLLEXPORT T & singleton< T >::instance = singleton< T >::get_instance(); +T & singleton< T >::m_instance = singleton< T >::get_instance(); } // namespace serialization } // namespace boost +#include // pops abi_suffix.hpp pragmas + #ifdef BOOST_MSVC #pragma warning(pop) #endif diff --git a/src/extended_type_info.cpp b/src/extended_type_info.cpp index 13a60c3e..364fe56d 100644 --- a/src/extended_type_info.cpp +++ b/src/extended_type_info.cpp @@ -125,6 +125,7 @@ BOOST_SERIALIZATION_DECL void extended_type_info::key_unregister() const{ if(NULL == get_key()) return; + BOOST_ASSERT(! singleton::is_destroyed()); if(! singleton::is_destroyed()){ detail::ktmap & x = singleton::get_mutable_instance(); detail::ktmap::iterator start = x.lower_bound(this); diff --git a/src/extended_type_info_typeid.cpp b/src/extended_type_info_typeid.cpp index 5669dfa7..19cbf00e 100644 --- a/src/extended_type_info_typeid.cpp +++ b/src/extended_type_info_typeid.cpp @@ -95,6 +95,7 @@ BOOST_SERIALIZATION_DECL void extended_type_info_typeid_0::type_unregister() { if(NULL != m_ti){ + BOOST_ASSERT(! singleton::is_destroyed()); if(! singleton::is_destroyed()){ tkmap & x = singleton::get_mutable_instance(); tkmap::iterator start = x.lower_bound(this); diff --git a/src/singleton.cpp b/src/singleton.cpp index 70855f60..de408030 100644 --- a/src/singleton.cpp +++ b/src/singleton.cpp @@ -22,17 +22,5 @@ BOOST_SERIALIZATION_DECL bool & singleton_module::get_lock(){ return lock; } -#if 0 -BOOST_SERIALIZATION_DECL void singleton_module::lock(){ - get_lock() = true; -} -BOOST_SERIALIZATION_DECL void singleton_module::unlock(){ - get_lock() = false; -} -BOOST_SERIALIZATION_DECL bool singleton_module::is_locked(){ - return get_lock(); -} -#endif - } // namespace serialization } // namespace boost diff --git a/src/void_cast.cpp b/src/void_cast.cpp index 90099933..40513030 100644 --- a/src/void_cast.cpp +++ b/src/void_cast.cpp @@ -276,6 +276,7 @@ void_caster::recursive_register(bool includes_virtual_base) const { BOOST_SERIALIZATION_DECL void void_caster::recursive_unregister() const { + BOOST_ASSERT(! void_caster_registry::is_destroyed()); if(void_caster_registry::is_destroyed()) return;