Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make SIMIX_context_new() accept std::function
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 19 May 2016 14:20:06 +0000 (16:20 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 23 May 2016 07:05:21 +0000 (09:05 +0200)
src/simix/Context.cpp
src/simix/smx_private.h
src/simix/smx_process.cpp
src/xbt/parmap.cpp

index a780e56..d397833 100644 (file)
@@ -30,14 +30,14 @@ void SIMIX_process_set_cleanup_function(
  * \param cleanup_func the function to call when the context stops
  */
 smx_context_t SIMIX_context_new(
-  xbt_main_func_t code, int argc, char **argv,
+  std::function<void()> code,
   void_pfn_smxprocess_t cleanup_func,
   smx_process_t simix_process)
 {
   if (!simix_global)
     xbt_die("simix is not initialized, please call MSG_init first");
   return simix_global->context_factory->create_context(
-    simgrid::simix::wrap_main(code, argc, argv), cleanup_func, simix_process);
+    std::move(code), cleanup_func, simix_process);
 }
 
 namespace simgrid {
index d038451..02907e5 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef _SIMIX_PRIVATE_H
 #define _SIMIX_PRIVATE_H
 
+#include <functional>
+
 #include "src/internal_config.h"
 #include "simgrid/simix.h"
 #include "surf/surf.h"
@@ -99,7 +101,7 @@ XBT_PRIVATE void SIMIX_context_mod_init(void);
 XBT_PRIVATE void SIMIX_context_mod_exit(void);
 
 XBT_PRIVATE smx_context_t SIMIX_context_new(
-  xbt_main_func_t code, int argc, char **argv,
+  std::function<void()> code,
   void_pfn_smxprocess_t cleanup_func,
   smx_process_t simix_process);
 
index 9c2273f..08644bb 100644 (file)
@@ -156,7 +156,7 @@ void create_maestro(std::function<void()> code)
   XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
 
   if (!code) {
-    maestro->context = SIMIX_context_new(NULL, 0, nullptr, NULL, maestro);
+    maestro->context = SIMIX_context_new(std::function<void()>(), NULL, maestro);
   } else {
     if (!simix_global)
       xbt_die("simix is not initialized, please call MSG_init first");
@@ -315,7 +315,9 @@ smx_process_t SIMIX_process_create(
 
 
     XBT_VERB("Create context %s", process->name);
-    process->context = SIMIX_context_new(code, argc, argv, simix_global->cleanup_process_function, process);
+    process->context = SIMIX_context_new(
+      simgrid::simix::wrap_main(code, argc, argv),
+      simix_global->cleanup_process_function, process);
 
     process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
     XBT_RUNNING_CTX_INITIALIZE(process->running_ctx);
index b456047..2445b0b 100644 (file)
@@ -272,7 +272,7 @@ static void *xbt_parmap_worker_main(void *arg)
   xbt_parmap_thread_data_t data = (xbt_parmap_thread_data_t) arg;
   xbt_parmap_t parmap = data->parmap;
   unsigned round = 0;
-  smx_context_t context = SIMIX_context_new(NULL, 0, NULL, NULL, NULL);
+  smx_context_t context = SIMIX_context_new(std::function<void()>(), NULL, NULL);
   SIMIX_context_set_current(context);
 
   XBT_DEBUG("New worker thread created");