Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't destroy synchro in a simcall, this drives the JVM nuts
[simgrid.git] / src / simix / BoostContext.cpp
index f2e5cee..debd695 100644 (file)
@@ -8,6 +8,10 @@
 
 #include <cstdint>
 
+#include <functional>
+#include <utility>
+#include <vector>
+
 #include <boost/context/all.hpp>
 
 #include <xbt/log.h>
@@ -25,11 +29,10 @@ namespace simix {
 
 class BoostSerialContext : public BoostContext {
 public:
-  BoostSerialContext(xbt_main_func_t code,
-      int argc, char **argv,
+  BoostSerialContext(std::function<void()> code,
       void_pfn_smxprocess_t cleanup_func,
       smx_process_t process)
-    : BoostContext(code, argc, argv, cleanup_func, process) {}
+    : BoostContext(std::move(code), cleanup_func, process) {}
   void stop() override;
   void suspend() override;
   void resume();
@@ -38,11 +41,10 @@ public:
 #ifdef CONTEXT_THREADS
 class BoostParallelContext : public BoostContext {
 public:
-  BoostParallelContext(xbt_main_func_t code,
-      int argc, char **argv,
+  BoostParallelContext(std::function<void()> code,
       void_pfn_smxprocess_t cleanup_func,
       smx_process_t process)
-    : BoostContext(code, argc, argv, cleanup_func, process) {}
+    : BoostContext(std::move(code), cleanup_func, process) {}
   void stop() override;
   void suspend() override;
   void resume();
@@ -88,21 +90,20 @@ BoostContextFactory::~BoostContextFactory()
 #endif
 }
 
-smx_context_t BoostContextFactory::create_context(
-  xbt_main_func_t code, int argc, char ** argv,
+smx_context_t BoostContextFactory::create_context(std::function<void()>  code,
   void_pfn_smxprocess_t cleanup_func, smx_process_t process)
 {
   BoostContext* context = nullptr;
   if (BoostContext::parallel_)
 #ifdef CONTEXT_THREADS
     context = this->new_context<BoostParallelContext>(
-      code, argc, argv, cleanup_func, process);
+      std::move(code), cleanup_func, process);
 #else
     xbt_die("No support for parallel execution");
 #endif
   else
     context = this->new_context<BoostSerialContext>(
-      code, argc, argv, cleanup_func, process);
+      std::move(code), cleanup_func, process);
   return context;
 }
 
@@ -139,16 +140,14 @@ static void smx_ctx_boost_wrapper(std::intptr_t arg)
   context->stop();
 }
 
-BoostContext::BoostContext(xbt_main_func_t code,
-    int argc, char **argv,
-    void_pfn_smxprocess_t cleanup_func,
-    smx_process_t process)
-  : Context(code, argc, argv, cleanup_func, process)
+BoostContext::BoostContext(std::function<void()> code,
+    void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+  : Context(std::move(code), cleanup_func, process)
 {
 
   /* if the user provided a function for the process then use it,
      otherwise it is the context for maestro */
-  if (code) {
+  if (has_code()) {
     this->stack_ = SIMIX_context_stack_new();
     // We need to pass the bottom of the stack to make_fcontext,
     // depending on the stack direction it may be the lower or higher address:
@@ -192,7 +191,7 @@ void BoostContext::resume()
     (intptr_t) this);
 #else
   boost::context::jump_fcontext(
-    &boost_maestro_context_->fc_, this->fc_,
+    &maestro_context_->fc_, this->fc_,
     (intptr_t) this);
 #endif
 }