From: Arnaud Giersch Date: Tue, 12 Sep 2017 21:13:16 +0000 (+0200) Subject: ContextBoost: add support for Boost versions above 1.61. X-Git-Tag: v3_17~132 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8da9378a1529be135b2b980915e77cd958134c98 ContextBoost: add support for Boost versions above 1.61. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f813d5175..342de40b88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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.") diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index fc36369b83..237de080f3 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -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(arg); +#else + static_cast(arg.data)[0]->fc_ = arg.fctx; + BoostContext* context = static_cast(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(to)); -#else +#elif BOOST_VERSION < 106100 boost::context::jump_fcontext(&from->fc_, to->fc_, reinterpret_cast(to)); +#else + BoostContext* ctx[2] = {from, to}; + boost::context::detail::transfer_t arg = boost::context::detail::jump_fcontext(to->fc_, ctx); + static_cast(arg.data)[0]->fc_ = arg.fctx; #endif } @@ -158,10 +167,11 @@ BoostContext::BoostContext(std::function 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(); diff --git a/src/kernel/context/ContextBoost.hpp b/src/kernel/context/ContextBoost.hpp index f7f40db3e3..0c6a35ba71 100644 --- a/src/kernel/context/ContextBoost.hpp +++ b/src/kernel/context/ContextBoost.hpp @@ -7,7 +7,11 @@ #define SIMGRID_SIMIX_BOOST_CONTEXT_HPP #include +#if BOOST_VERSION < 106100 #include +#else +#include +#endif #include #include @@ -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;