Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #1 from mquinson/master
[simgrid.git] / src / simix / RawContext.cpp
index 6247479..98c07e8 100644 (file)
@@ -4,7 +4,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-/** \file Rawcontext.cpp 
+/** \file RawContext.cpp 
   * Fast context switching inspired from SystemV ucontexts.
   *
   * In contrast to System V context, it does not touch the signal mask
@@ -13,6 +13,9 @@
 
 #include <math.h>
 
+#include <utility>
+#include <functional>
+
 #include <xbt/log.h>
 #include <xbt/parmap.h>
 #include <xbt/dynar.h>
@@ -38,8 +41,7 @@ protected:
   void* stack_top_ = nullptr;
 public:
   friend class RawContextFactory;
-  RawContext(xbt_main_func_t code,
-          int argc, char **argv,
+  RawContext(std::function<void()> code,
           void_pfn_smxprocess_t cleanup_func,
           smx_process_t process);
   ~RawContext();
@@ -59,10 +61,8 @@ class RawContextFactory : public ContextFactory {
 public:
   RawContextFactory();
   ~RawContextFactory();
-  RawContext* create_context(
-    xbt_main_func_t, int, char **, void_pfn_smxprocess_t,
-    smx_process_t process
-    ) override;
+  RawContext* create_context(std::function<void()> code,
+    void_pfn_smxprocess_t, smx_process_t process) override;
   void run_all() override;
 private:
   void run_all_adaptative();
@@ -311,12 +311,10 @@ RawContextFactory::~RawContextFactory()
 #endif
 }
 
-RawContext* RawContextFactory::create_context(
-    xbt_main_func_t code, int argc, char ** argv,
-    void_pfn_smxprocess_t cleanup,
-    smx_process_t process)
+RawContext* RawContextFactory::create_context(std::function<void()> code,
+    void_pfn_smxprocess_t cleanup, smx_process_t process)
 {
-  return this->new_context<RawContext>(code, argc, argv,
+  return this->new_context<RawContext>(std::move(code),
     cleanup, process);
 }
 
@@ -327,13 +325,11 @@ void RawContext::wrapper(void* arg)
   context->stop();
 }
 
-RawContext::RawContext(
-    xbt_main_func_t code, int argc, char ** argv,
-    void_pfn_smxprocess_t cleanup,
-    smx_process_t process)
-  : Context(code, argc, argv, cleanup, process)
+RawContext::RawContext(std::function<void()> code,
+    void_pfn_smxprocess_t cleanup, smx_process_t process)
+  : Context(std::move(code), cleanup, process)
 {
-   if (code) {
+   if (has_code()) {
      this->stack_ = SIMIX_context_stack_new();
      this->stack_top_ = raw_makecontext(this->stack_,
                          smx_context_usable_stack_size,