Boost logo

Boost-Commit :

From: ramey_at_[hidden]
Date: 2007-10-29 15:49:45


Author: ramey
Date: 2007-10-29 15:49:44 EDT (Mon, 29 Oct 2007)
New Revision: 40562
URL: http://svn.boost.org/trac/boost/changeset/40562

Log:
First implementation of thread safe lock free serialization
Text files modified:
   branches/serialization_next_release/boost/libs/serialization/test/test_derived.cpp | 24 +++--
   branches/serialization_next_release/boost/libs/serialization/test/test_exported.cpp | 26 ++++-
   branches/serialization_next_release/boost/libs/serialization/test/test_no_rtti.cpp | 90 +++++++++++++++------
   branches/serialization_next_release/boost/libs/serialization/test/test_registered.cpp | 19 ++-
   branches/serialization_next_release/boost/libs/serialization/test/test_tools.hpp | 7 +
   branches/serialization_next_release/boost/libs/serialization/test/test_unregistered.cpp | 30 +++++-
   branches/serialization_next_release/boost/libs/serialization/test/test_void_cast.cpp | 162 +++++++++++++++++++++------------------
   7 files changed, 222 insertions(+), 136 deletions(-)

Modified: branches/serialization_next_release/boost/libs/serialization/test/test_derived.cpp
==============================================================================
--- branches/serialization_next_release/boost/libs/serialization/test/test_derived.cpp (original)
+++ branches/serialization_next_release/boost/libs/serialization/test/test_derived.cpp 2007-10-29 15:49:44 EDT (Mon, 29 Oct 2007)
@@ -69,12 +69,14 @@
     // Warning, the current type id system does not yield true
     // type id for non-polymorphic types
     const boost::serialization::extended_type_info & this_type
- = * boost::serialization::type_info_implementation<base>::type
- ::find();
+ = boost::serialization::singleton<
+ boost::serialization::type_info_implementation<base>::type
+ >::get_const_instance();
     // retrieve the true type of the object pointed to
- const boost::serialization::extended_type_info & true_type
- = * boost::serialization::type_info_implementation<base>::type
- ::get_derived_extended_type_info(*b1);
+ const boost::serialization::extended_type_info & true_type
+ = * boost::serialization::singleton<
+ boost::serialization::type_info_implementation<base>::type
+ >::get_const_instance().get_derived_extended_type_info(*b1);
 
     BOOST_WARN_MESSAGE(
         !(this_type == true_type),
@@ -107,12 +109,14 @@
     // Warning, the current type id system does not yield true
     // type id for non-polymorphic types
     const boost::serialization::extended_type_info & this_type
- = * boost::serialization::type_info_implementation<base>::type
- ::find();
+ = boost::serialization::singleton<
+ boost::serialization::type_info_implementation<base>::type
+ >::get_const_instance();
     // retrieve the true type of the object pointed to
- const boost::serialization::extended_type_info & true_type
- = * boost::serialization::type_info_implementation<base>::type
- ::get_derived_extended_type_info(*b1);
+ const boost::serialization::extended_type_info & true_type
+ = * boost::serialization::singleton<
+ boost::serialization::type_info_implementation<base>::type
+ >::get_const_instance().get_derived_extended_type_info(*b1);
             
     BOOST_WARN_MESSAGE(
         ! (this_type == true_type),

Modified: branches/serialization_next_release/boost/libs/serialization/test/test_exported.cpp
==============================================================================
--- branches/serialization_next_release/boost/libs/serialization/test/test_exported.cpp (original)
+++ branches/serialization_next_release/boost/libs/serialization/test/test_exported.cpp 2007-10-29 15:49:44 EDT (Mon, 29 Oct 2007)
@@ -100,19 +100,29 @@
     // through a pointer to a base class
     ia >> BOOST_SERIALIZATION_NVP(rb1);
     BOOST_CHECK_MESSAGE(
- boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_base>
- ::type::get_derived_extended_type_info(*rb1),
+ & boost::serialization::singleton<
+ boost::serialization::type_info_implementation<polymorphic_derived1>
+ ::type
+ >::get_const_instance()
+ ==
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<polymorphic_base>
+ ::type
+ >::get_const_instance().get_derived_extended_type_info(*rb1),
         "restored pointer b1 not of correct type"
     );
 
     ia >> BOOST_SERIALIZATION_NVP(rb2);
     BOOST_CHECK_MESSAGE(
- boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_base>
- ::type::get_derived_extended_type_info(*rb2),
+ & boost::serialization::singleton<
+ boost::serialization::type_info_implementation<polymorphic_derived2>
+ ::type
+ >::get_const_instance()
+ ==
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<polymorphic_base>
+ ::type
+ >::get_const_instance().get_derived_extended_type_info(*rb2),
         "restored pointer b2 not of correct type"
     );
 

Modified: branches/serialization_next_release/boost/libs/serialization/test/test_no_rtti.cpp
==============================================================================
--- branches/serialization_next_release/boost/libs/serialization/test/test_no_rtti.cpp (original)
+++ branches/serialization_next_release/boost/libs/serialization/test/test_no_rtti.cpp 2007-10-29 15:49:44 EDT (Mon, 29 Oct 2007)
@@ -29,6 +29,8 @@
 
 #include <boost/archive/archive_exception.hpp>
 #include "test_tools.hpp"
+#include <boost/preprocessor/stringize.hpp>
+#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
 
 #include <boost/serialization/nvp.hpp>
 #include <boost/serialization/base_object.hpp>
@@ -73,10 +75,12 @@
 BOOST_CLASS_EXPORT(polymorphic_derived1)
 
 const char * polymorphic_derived1::get_key() const {
- const boost::serialization::extended_type_info *eti
- = boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::find();
- return eti->get_key();
+ return
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived1
+ >::type
+ >::get_const_instance().get_key();
 }
 
 class polymorphic_derived2 : public polymorphic_base
@@ -100,17 +104,19 @@
 
 const char * polymorphic_derived2::get_key() const {
     // use the exported key as the identifier
- const boost::serialization::extended_type_info *eti
- = boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::find();
- return eti->get_key();
+ return
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived2
+ >::type
+ >::get_const_instance().get_key();
 }
 
 // save derived polymorphic class
 void save_derived(const char *testfile)
 {
     test_ostream os(testfile, TEST_STREAM_FLAGS);
- test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
+ test_oarchive oa(os);
 
     polymorphic_derived1 *rd1 = new polymorphic_derived1;
     polymorphic_derived2 *rd2 = new polymorphic_derived2;
@@ -134,7 +140,7 @@
 void load_derived(const char *testfile)
 {
     test_istream is(testfile, TEST_STREAM_FLAGS);
- test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
+ test_iarchive ia(is);
 
     polymorphic_derived1 *rd1 = NULL;
     polymorphic_derived2 *rd2 = NULL;
@@ -142,20 +148,36 @@
     ia >> BOOST_SERIALIZATION_NVP(rd1);
 
     BOOST_CHECK_MESSAGE(
- boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::get_derived_extended_type_info(*rd1),
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived1
+ >::type
+ >::get_const_instance()
+ ==
+ * boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived1
+ >::type
+ >::get_const_instance().get_derived_extended_type_info(*rd1)
+ ,
         "restored pointer d1 not of correct type"
     );
 
     ia >> BOOST_SERIALIZATION_NVP(rd2);
 
     BOOST_CHECK_MESSAGE(
- boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::get_derived_extended_type_info(*rd2),
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived2
+ >::type
+ >::get_const_instance()
+ ==
+ * boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived2
+ >::type
+ >::get_const_instance().get_derived_extended_type_info(*rd2)
+ ,
         "restored pointer d2 not of correct type"
     );
 
@@ -173,10 +195,18 @@
     );
 
     BOOST_CHECK_MESSAGE(
- boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_base>
- ::type::get_derived_extended_type_info(*rb1),
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived1
+ >::type
+ >::get_const_instance()
+ ==
+ * boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_base
+ >::type
+ >::get_const_instance().get_derived_extended_type_info(*rb1)
+ ,
         "restored pointer b1 not of correct type"
     );
 
@@ -188,10 +218,18 @@
     );
 
     BOOST_CHECK_MESSAGE(
- boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_base>
- ::type::get_derived_extended_type_info(*rb2),
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived2
+ >::type
+ >::get_const_instance()
+ ==
+ * boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_base
+ >::type
+ >::get_const_instance().get_derived_extended_type_info(*rb2)
+ ,
         "restored pointer b2 not of correct type"
     );
 

Modified: branches/serialization_next_release/boost/libs/serialization/test/test_registered.cpp
==============================================================================
--- branches/serialization_next_release/boost/libs/serialization/test/test_registered.cpp (original)
+++ branches/serialization_next_release/boost/libs/serialization/test/test_registered.cpp 2007-10-29 15:49:44 EDT (Mon, 29 Oct 2007)
@@ -97,8 +97,10 @@
     ia >> BOOST_SERIALIZATION_NVP(rd1);
 
     const boost::serialization::extended_type_info * p1;
- p1 = boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::find();
+ p1 = boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived1
+ >::type>::get_const_instance();
 
     BOOST_CHECK(NULL != p1);
 
@@ -114,8 +116,9 @@
 
     BOOST_CHECK_MESSAGE(
         boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_derived2>
+ ::type::get_instance()
+ ==
+ boost::serialization::type_info_implementation<polymorphic_derived2>
             ::type::get_derived_extended_type_info(*rd2),
         "restored pointer d2 not of correct type"
     );
@@ -134,7 +137,7 @@
     );
 
     p1 = boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::find();
+ ::type::get_instance();
 
     BOOST_CHECK(NULL != p1);
 
@@ -154,7 +157,7 @@
 
     BOOST_CHECK_MESSAGE(
         boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::find()
+ ::type::get_instance()
         == boost::serialization::type_info_implementation<polymorphic_base>
             ::type::get_derived_extended_type_info(*rb2),
         "restored pointer b2 not of correct type"
@@ -200,7 +203,7 @@
 
     BOOST_CHECK_MESSAGE(
         boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::find()
+ ::type::get_instance()
         == boost::serialization::type_info_implementation<polymorphic_base>
             ::type::get_derived_extended_type_info(*rb1),
         "restored pointer b1 not of correct type"
@@ -208,7 +211,7 @@
 
     BOOST_CHECK_MESSAGE(
         boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::find()
+ ::type::get_instance()
         == boost::serialization::type_info_implementation<polymorphic_base>
             ::type::get_derived_extended_type_info(*rb2),
         "restored pointer b2 not of correct type"

Modified: branches/serialization_next_release/boost/libs/serialization/test/test_tools.hpp
==============================================================================
--- branches/serialization_next_release/boost/libs/serialization/test/test_tools.hpp (original)
+++ branches/serialization_next_release/boost/libs/serialization/test/test_tools.hpp 2007-10-29 15:49:44 EDT (Mon, 29 Oct 2007)
@@ -173,8 +173,12 @@
 
 int test_main(int argc, char * argv[]);
 
+#include <boost/serialization/singleton.hpp>
+
 int
 main(int argc, char * argv[]){
+ boost::serialization::global_lock::get_mutable_instance().lock();
+
     BOOST_TRY{
         test_main(argc, argv);
     }
@@ -187,6 +191,9 @@
         BOOST_FAIL("failed with uncaught exception:");
     }
     BOOST_CATCH_END
+
+ boost::serialization::global_lock::get_mutable_instance().unlock();
+
     return boost::report_errors();
 }
 

Modified: branches/serialization_next_release/boost/libs/serialization/test/test_unregistered.cpp
==============================================================================
--- branches/serialization_next_release/boost/libs/serialization/test/test_unregistered.cpp (original)
+++ branches/serialization_next_release/boost/libs/serialization/test/test_unregistered.cpp 2007-10-29 15:49:44 EDT (Mon, 29 Oct 2007)
@@ -199,20 +199,34 @@
 
     BOOST_CHECK_MESSAGE(NULL != rb1, "Load resulted in NULL pointer");
     BOOST_CHECK_MESSAGE(
- boost::serialization::type_info_implementation<polymorphic_derived1>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_base>
- ::type::get_derived_extended_type_info(*rb1),
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived1
+ >::type
+ >::get_const_instance()
+ ==
+ * boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_base
+ >::type
+ >::get_const_instance().get_derived_extended_type_info(*rb1),
         "restored pointer b1 not of correct type"
     );
 
     ia >> BOOST_SERIALIZATION_NVP(rb2);
     BOOST_CHECK_MESSAGE(NULL != rb2, "Load resulted in NULL pointer");
     BOOST_CHECK_MESSAGE(
- boost::serialization::type_info_implementation<polymorphic_derived2>
- ::type::find()
- == boost::serialization::type_info_implementation<polymorphic_base>
- ::type::get_derived_extended_type_info(*rb2),
+ boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_derived2
+ >::type
+ >::get_const_instance()
+ ==
+ * boost::serialization::singleton<
+ boost::serialization::type_info_implementation<
+ polymorphic_base
+ >::type
+ >::get_const_instance().get_derived_extended_type_info(*rb2),
         "restored pointer b2 not of correct type"
     );
 

Modified: branches/serialization_next_release/boost/libs/serialization/test/test_void_cast.cpp
==============================================================================
--- branches/serialization_next_release/boost/libs/serialization/test/test_void_cast.cpp (original)
+++ branches/serialization_next_release/boost/libs/serialization/test/test_void_cast.cpp 2007-10-29 15:49:44 EDT (Mon, 29 Oct 2007)
@@ -31,103 +31,113 @@
     char d[32];
 };
 
+template<class T>
+const boost::serialization::extended_type_info & eti(){
+ return boost::serialization::singleton<
+ boost::serialization::extended_type_info_typeid<T>
+ >::get_const_instance();
+}
+
 int
 test_main( int /* argc */, char* /* argv */[] )
 {
- MostDerived d;
- MostDerived* pd =& d;
- Derived* pc = static_cast<Derived*>(pd);
-
- Base2* pb = static_cast<Base2*>(pd);
- Base1* pa = static_cast<Base1*>(pd);
-
+ MostDerived md;
+ MostDerived* pmd =& md;
+ Derived* pd = static_cast<Derived*>(pmd);
+
+ Base2* pb2 = static_cast<Base2*>(pmd);
+ Base1* pb1 = static_cast<Base1*>(pd);
+
+ void* vpmd = static_cast<void*>(pmd);
+ void* vpb1 = static_cast<void*>(pb1);
+ void* vpb2 = static_cast<void*>(pb2);
     void* vpd = static_cast<void*>(pd);
- void* vpc = static_cast<void*>(pc);
- void* vpb = static_cast<void*>(pb);
- void* vpa = static_cast<void*>(pa);
 
     // simple casts only requiring table lookup
- BOOST_CHECK(vpc == boost::serialization::void_downcast(
- * boost::serialization::extended_type_info_typeid<Derived>::find(),
- * boost::serialization::extended_type_info_typeid<Base1>::find(),
- vpa
- ));
- BOOST_CHECK(vpa == boost::serialization::void_upcast(
- * boost::serialization::extended_type_info_typeid<Derived>::find(),
- * boost::serialization::extended_type_info_typeid<Base1>::find(),
- vpc
- ));
- BOOST_CHECK(vpc == boost::serialization::void_downcast(
- * boost::serialization::extended_type_info_typeid<Derived>::find(),
- * boost::serialization::extended_type_info_typeid<Base2>::find(),
- vpb
- ));
- BOOST_CHECK(vpb == boost::serialization::void_upcast(
- * boost::serialization::extended_type_info_typeid<Derived>::find(),
- * boost::serialization::extended_type_info_typeid<Base2>::find(),
- vpc
+ BOOST_CHECK(vpd == boost::serialization::void_downcast(
+ eti<Derived>(),
+ eti<Base1>(),
+ vpb1
+ ));
+ BOOST_CHECK(vpb1 == boost::serialization::void_upcast(
+ eti<Derived>(),
+ eti<Base1>(),
+ vpd
     ));
     BOOST_CHECK(vpd == boost::serialization::void_downcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Derived>::find(),
- vpc
- ));
- BOOST_CHECK(vpc == boost::serialization::void_upcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Derived>::find(),
+ eti<Derived>(),
+ eti<Base2>(),
+ vpb2
+ ));
+ BOOST_CHECK(vpb2 == boost::serialization::void_upcast(
+ eti<Derived>(),
+ eti<Base2>(),
         vpd
     ));
- // note relationship between MostDerived and Base1 is automatically derived
- BOOST_CHECK(vpd == boost::serialization::void_downcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Base1>::find(),
- vpa
- ));
- BOOST_CHECK(vpa == boost::serialization::void_upcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Base1>::find(),
+ BOOST_CHECK(vpmd == boost::serialization::void_downcast(
+ eti<MostDerived>(),
+ eti<Derived>(),
         vpd
     ));
+ BOOST_CHECK(vpd == boost::serialization::void_upcast(
+ eti<MostDerived>(),
+ eti<Derived>(),
+ vpmd
+ ));
+ // note relationship between MostDerived and Base1 is automatically derived
+ BOOST_CHECK(vpmd == boost::serialization::void_downcast(
+ eti<MostDerived>(),
+ eti<Base1>(),
+ vpb1
+ ));
+ BOOST_CHECK(vpb1 == boost::serialization::void_upcast(
+ eti<MostDerived>(),
+ eti<Base1>(),
+ vpmd
+ ));
 
     // note relationship between MostDerived and Base2 is automatically derived
- BOOST_CHECK(vpd == boost::serialization::void_downcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Base2>::find(),
- vpb
- ));
- BOOST_CHECK(vpb == boost::serialization::void_upcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Base2>::find(),
- vpd
+ BOOST_CHECK(vpmd == boost::serialization::void_downcast(
+ eti<MostDerived>(),
+ eti<Base2>(),
+ vpb2
+ ));
+ BOOST_CHECK(vpb2 == boost::serialization::void_upcast(
+ eti<MostDerived>(),
+ eti<Base2>(),
+ vpmd
     ));
 
+ // note: currently derivations are not optimised. See void_cast.cpp
+ // for and explanation. These should still work though.
+
     // need to double check to validate speed up optimization of derivations
- BOOST_CHECK(vpd == boost::serialization::void_downcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Base1>::find(),
- vpa
- ));
- BOOST_CHECK(vpa == boost::serialization::void_upcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Base1>::find(),
- vpd
- ));
- BOOST_CHECK(vpd == boost::serialization::void_downcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Base2>::find(),
- vpb
- ));
- BOOST_CHECK(vpb == boost::serialization::void_upcast(
- * boost::serialization::extended_type_info_typeid<MostDerived>::find(),
- * boost::serialization::extended_type_info_typeid<Base2>::find(),
- vpd
+ BOOST_CHECK(vpmd == boost::serialization::void_downcast(
+ eti<MostDerived>(),
+ eti<Base1>(),
+ vpb1
+ ));
+ BOOST_CHECK(vpb1 == boost::serialization::void_upcast(
+ eti<MostDerived>(),
+ eti<Base1>(),
+ vpmd
+ ));
+ BOOST_CHECK(vpmd == boost::serialization::void_downcast(
+ eti<MostDerived>(),
+ eti<Base2>(),
+ vpb2
+ ));
+ BOOST_CHECK(vpb2 == boost::serialization::void_upcast(
+ eti<MostDerived>(),
+ eti<Base2>(),
+ vpmd
     ));
 
     // check things that should fail
     BOOST_CHECK(NULL == boost::serialization::void_downcast(
- * boost::serialization::extended_type_info_typeid<Base2>::find(),
- * boost::serialization::extended_type_info_typeid<Base1>::find(),
- vpa
+ eti<Base2>(),
+ eti<Base1>(),
+ vpb1
     ));
 
     // note that a fundamental feature is that derived/base pairs are created


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