Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ContextBoost: add support for Boost versions above 1.61.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 12 Sep 2017 21:13:16 +0000 (23:13 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 12 Sep 2017 21:27:34 +0000 (23:27 +0200)
CMakeLists.txt
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextBoost.hpp

index 4f813d5..342de40 100644 (file)
@@ -273,16 +273,8 @@ endif()
 find_package(Boost COMPONENTS context)
 set(Boost_FOUND 1) # This component is optional
 if(Boost_CONTEXT_FOUND)
-  if (Boost_VERSION LESS 105600)
-    message("Found Boost.Context API v1")
-    set(HAVE_BOOST_CONTEXTS 1)
-  elseif(Boost_VERSION LESS 106100)
-    message("Found Boost.Context API v2")
-    set(HAVE_BOOST_CONTEXTS 2)
-  else()
-    message("   WARNING : our implementation of Boost context factory is not compatible with Boost >=1.61 yet.")
-    set(HAVE_BOOST_CONTEXTS 0)
-  endif()
+  message("Found Boost.Context")
+  set(HAVE_BOOST_CONTEXTS 1)
 else()
   message ("   boost        : found.")
   message ("   boost-context: missing. Install libboost-context-dev for this optional feature.")
index fc36369..237de08 100644 (file)
@@ -127,9 +127,14 @@ void BoostContextFactory::run_all()
 
 // BoostContext
 
-void BoostContext::smx_ctx_boost_wrapper(std::intptr_t arg)
+void BoostContext::smx_ctx_boost_wrapper(BoostContext::ctx_arg_type arg)
 {
+#if BOOST_VERSION < 106100
   BoostContext* context = reinterpret_cast<BoostContext*>(arg);
+#else
+  static_cast<BoostContext**>(arg.data)[0]->fc_ = arg.fctx;
+  BoostContext* context                         = static_cast<BoostContext**>(arg.data)[1];
+#endif
   (*context)();
   context->stop();
 }
@@ -138,8 +143,12 @@ inline void BoostContext::smx_ctx_boost_jump_fcontext(BoostContext* from, BoostC
 {
 #if BOOST_VERSION < 105600
   boost::context::jump_fcontext(from->fc_, to->fc_, reinterpret_cast<intptr_t>(to));
-#else
+#elif BOOST_VERSION < 106100
   boost::context::jump_fcontext(&from->fc_, to->fc_, reinterpret_cast<intptr_t>(to));
+#else
+  BoostContext* ctx[2]                          = {from, to};
+  boost::context::detail::transfer_t arg        = boost::context::detail::jump_fcontext(to->fc_, ctx);
+  static_cast<BoostContext**>(arg.data)[0]->fc_ = arg.fctx;
 #endif
 }
 
@@ -158,10 +167,11 @@ BoostContext::BoostContext(std::function<void()> code,
 #else
     void* stack = this->stack_;
 #endif
-    this->fc_ = boost::context::make_fcontext(
-                      stack,
-                      smx_context_usable_stack_size,
-                      smx_ctx_boost_wrapper);
+#if BOOST_VERSION < 106100
+    this->fc_ = boost::context::make_fcontext(stack, smx_context_usable_stack_size, smx_ctx_boost_wrapper);
+#else
+    this->fc_ = boost::context::detail::make_fcontext(stack, smx_context_usable_stack_size, smx_ctx_boost_wrapper);
+#endif
   } else {
 #if BOOST_VERSION < 105600
     this->fc_ = new boost::context::fcontext_t();
index f7f40db..0c6a35b 100644 (file)
@@ -7,7 +7,11 @@
 #define SIMGRID_SIMIX_BOOST_CONTEXT_HPP
 
 #include <boost/version.hpp>
+#if BOOST_VERSION < 106100
 #include <boost/context/fcontext.hpp>
+#else
+#include <boost/context/detail/fcontext.hpp>
+#endif
 #include <functional>
 #include <vector>
 
@@ -38,10 +42,15 @@ protected: // static
 
 #if BOOST_VERSION < 105600
   boost::context::fcontext_t* fc_ = nullptr;
-#else
+  typedef intptr_t ctx_arg_type;
+#elif BOOST_VERSION < 106100
   boost::context::fcontext_t fc_;
+  typedef intptr_t ctx_arg_type;
+#else
+  boost::context::detail::fcontext_t fc_;
+  typedef boost::context::detail::transfer_t ctx_arg_type;
 #endif
-  static void smx_ctx_boost_wrapper(intptr_t);
+  static void smx_ctx_boost_wrapper(ctx_arg_type);
   static void smx_ctx_boost_jump_fcontext(BoostContext*, BoostContext*);
 
   void* stack_ = nullptr;