Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ContextBoost: define helper function for jump_fcontext.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 12 Sep 2017 20:11:32 +0000 (22:11 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 12 Sep 2017 21:17:03 +0000 (23:17 +0200)
Also make smx_ctx_boost_wrapper() a static member of BoostContext.

src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextBoost.hpp

index 4c3958c..d36722c 100644 (file)
@@ -127,13 +127,22 @@ void BoostContextFactory::run_all()
 
 // BoostContext
 
-static void smx_ctx_boost_wrapper(std::intptr_t arg)
+void BoostContext::smx_ctx_boost_wrapper(std::intptr_t arg)
 {
   BoostContext* context = reinterpret_cast<BoostContext*>(arg);
   (*context)();
   context->stop();
 }
 
+inline void BoostContext::smx_ctx_boost_jump_fcontext(BoostContext* from, BoostContext* to)
+{
+#if BOOST_VERSION < 105600
+  boost::context::jump_fcontext(from->fc_, to->fc_, reinterpret_cast<intptr_t>(to));
+#else
+  boost::context::jump_fcontext(&from->fc_, to->fc_, reinterpret_cast<intptr_t>(to));
+#endif
+}
+
 BoostContext::BoostContext(std::function<void()> code,
     void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
   : Context(std::move(code), cleanup_func, process)
@@ -178,11 +187,7 @@ BoostContext::~BoostContext()
 void BoostContext::resume()
 {
   SIMIX_context_set_current(this);
-#if BOOST_VERSION < 105600
-  boost::context::jump_fcontext(maestro_context_->fc_, this->fc_, reinterpret_cast<intptr_t>(this));
-#else
-  boost::context::jump_fcontext(&maestro_context_->fc_, this->fc_, reinterpret_cast<intptr_t>(this));
-#endif
+  smx_ctx_boost_jump_fcontext(maestro_context_, this);
 }
 
 void BoostSerialContext::suspend()
@@ -202,11 +207,7 @@ void BoostSerialContext::suspend()
     next_context = static_cast<BoostSerialContext*>(maestro_context_);
   }
   SIMIX_context_set_current(static_cast<smx_context_t>(next_context));
-#if BOOST_VERSION < 105600
-  boost::context::jump_fcontext(this->fc_, next_context->fc_, reinterpret_cast<pintptr_t>(next_context));
-#else
-  boost::context::jump_fcontext(&this->fc_, next_context->fc_, reinterpret_cast<intptr_t>(next_context));
-#endif
+  smx_ctx_boost_jump_fcontext(this, next_context);
 }
 
 void BoostSerialContext::stop()
@@ -233,11 +234,7 @@ void BoostParallelContext::suspend()
   }
 
   SIMIX_context_set_current(static_cast<smx_context_t>(next_context));
-#if BOOST_VERSION < 105600
-  boost::context::jump_fcontext(this->fc_, next_context->fc_, reinterpret_cast<intptr_t>(next_context));
-#else
-  boost::context::jump_fcontext(&this->fc_, next_context->fc_, reinterpret_cast<intptr_t>(next_context));
-#endif
+  smx_ctx_boost_jump_fcontext(this, next_context);
 }
 
 void BoostParallelContext::stop()
@@ -255,11 +252,7 @@ void BoostParallelContext::resume()
   workers_context_[worker_id] = worker_context;
 
   SIMIX_context_set_current(this);
-#if BOOST_VERSION < 105600
-  boost::context::jump_fcontext(worker_context->fc_, this->fc_, reinterpret_cast<intptr_t>(this));
-#else
-  boost::context::jump_fcontext(&worker_context->fc_, this->fc_, reinterpret_cast<intptr_t>(this));
-#endif
+  smx_ctx_boost_jump_fcontext(worker_context, this);
 }
 
 #endif
index 9a2a2fb..f7f40db 100644 (file)
@@ -41,6 +41,9 @@ protected: // static
 #else
   boost::context::fcontext_t fc_;
 #endif
+  static void smx_ctx_boost_wrapper(intptr_t);
+  static void smx_ctx_boost_jump_fcontext(BoostContext*, BoostContext*);
+
   void* stack_ = nullptr;
 public:
   friend BoostContextFactory;