From d509dd175e358ed71fd0ef4337539ac460f2d2aa Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 18 Jun 2015 16:14:15 +0200 Subject: [PATCH] Add support for new Boost.Context API --- buildtools/Cmake/CompleteInFiles.cmake | 6 +++--- src/simix/smx_context_boost.cpp | 28 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/buildtools/Cmake/CompleteInFiles.cmake b/buildtools/Cmake/CompleteInFiles.cmake index abd7e8907a..456f61097c 100644 --- a/buildtools/Cmake/CompleteInFiles.cmake +++ b/buildtools/Cmake/CompleteInFiles.cmake @@ -123,11 +123,11 @@ endif() if(Boost_FOUND AND Boost_CONTEXT_FOUND) # We should use feature detection for this instead: if (Boost_VERSION LESS 105600) - message("Found suitable Boost.Context") + message("Found Boost.Context API v1") set(HAVE_BOOST_CONTEXT 1) else() - message("Found unsuitable version of Boost.Context (${Boost_VERSION}, up to 1.55 is currenly implemented)") - set(HAVE_BOOST_CONTEXT 0) + message("Found Boost.Context API v2") + set(HAVE_BOOST_CONTEXT 2) endif() else() set(HAVE_BOOST_CONTEXT 0) diff --git a/src/simix/smx_context_boost.cpp b/src/simix/smx_context_boost.cpp index 71d34f1872..1ddf0809ee 100644 --- a/src/simix/smx_context_boost.cpp +++ b/src/simix/smx_context_boost.cpp @@ -18,7 +18,11 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); typedef struct s_smx_ctx_boost { s_smx_ctx_base_t super; /* Fields of super implementation */ +#if HAVE_BOOST_CONTEXT == 1 boost::context::fcontext_t* fc; +#else + boost::context::fcontext_t fc; +#endif void* stack; } s_smx_ctx_boost_t, *smx_ctx_boost_t; @@ -130,7 +134,9 @@ smx_ctx_boost_create_context(xbt_main_func_t code, int argc, char **argv, smx_ctx_boost_wrapper); } else { context->stack = nullptr; +#if HAVE_BOOST_CONTEXT == 1 context->fc = new boost::context::fcontext_t(); +#endif if (boost_maestro_context == nullptr) boost_maestro_context = context; } @@ -143,8 +149,10 @@ static void smx_ctx_boost_free(smx_context_t c) smx_ctx_boost_t context = (smx_ctx_boost_t) c; if (!context) return; +#if HAVE_BOOST_CONTEXT == 1 if (!context->stack) delete context->fc; +#endif if ((smx_ctx_boost_t) c == boost_maestro_context) boost_maestro_context = nullptr; SIMIX_context_stack_delete(context->stack); @@ -182,16 +190,26 @@ static void smx_ctx_boost_suspend_serial(smx_context_t context) next_context = (smx_ctx_boost_t) boost_maestro_context; } SIMIX_context_set_current((smx_context_t) next_context); +#if HAVE_BOOST_CONTEXT == 1 boost::context::jump_fcontext( ((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context); +#else + boost::context::jump_fcontext( + &((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context); +#endif } static void smx_ctx_boost_resume_serial(smx_process_t first_process) { smx_ctx_boost_t context = (smx_ctx_boost_t) first_process->context; SIMIX_context_set_current((smx_context_t) context); +#if HAVE_BOOST_CONTEXT == 1 boost::context::jump_fcontext(boost_maestro_context->fc, context->fc, (intptr_t)context); +#else + boost::context::jump_fcontext(&boost_maestro_context->fc, context->fc, + (intptr_t)context); +#endif } static void smx_ctx_boost_runall_serial(void) @@ -231,8 +249,13 @@ static void smx_ctx_boost_suspend_parallel(smx_context_t context) } SIMIX_context_set_current((smx_context_t) next_context); +#if HAVE_BOOST_CONTEXT == 1 boost::context::jump_fcontext( ((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context); +#else + boost::context::jump_fcontext( + &((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context); +#endif } static void smx_ctx_boost_resume_parallel(smx_process_t process) @@ -245,8 +268,13 @@ static void smx_ctx_boost_resume_parallel(smx_process_t process) smx_ctx_boost_t context = (smx_ctx_boost_t) process->context; SIMIX_context_set_current((smx_context_t) context); +#if HAVE_BOOST_CONTEXT == 1 boost::context::jump_fcontext(worker_context->fc, context->fc, (intptr_t)context); +#else + boost::context::jump_fcontext(&worker_context->fc, context->fc, + (intptr_t)context); +#endif } static void smx_ctx_boost_runall_parallel(void) -- 2.20.1