Trying to get minGW to function for serialization library

simplify singleton.hpp and singleton.cpp
alter appveyor.yml
This commit is contained in:
Robert Ramey
2017-02-23 13:25:27 -08:00
parent 62bf8fc1e1
commit b0a794da38
7 changed files with 36 additions and 42 deletions

View File

@@ -47,6 +47,10 @@ archive_serializer_map<Archive>::insert(const basic_serializer * bs){
template<class Archive>
BOOST_ARCHIVE_OR_WARCHIVE_DECL void
archive_serializer_map<Archive>::erase(const basic_serializer * bs){
BOOST_ASSERT(! boost::serialization::singleton<
extra_detail::map<Archive>
>::is_destroyed()
);
if(boost::serialization::singleton<
extra_detail::map<Archive>
>::is_destroyed())

View File

@@ -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 <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
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
// 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 T>
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 &>(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<class T>
BOOST_DLLEXPORT T & singleton< T >::instance = singleton< T >::get_instance();
T & singleton< T >::m_instance = singleton< T >::get_instance();
} // namespace serialization
} // namespace boost
#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif