Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Use std::function for the maestro callback instead of void(void*)
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Feb 2016 10:58:14 +0000 (11:58 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Feb 2016 10:58:32 +0000 (11:58 +0100)
include/simgrid/simix.hpp
src/simix/smx_global.cpp
src/simix/smx_process.cpp

index 3d3e660..fb3fd5a 100644 (file)
@@ -232,6 +232,9 @@ public:
   virtual void attach_stop() = 0;
 };
 
   virtual void attach_stop() = 0;
 };
 
+XBT_PUBLIC(void) set_maestro(std::function<void()> code);
+XBT_PUBLIC(void) create_maestro(std::function<void()> code);
+
 }
 }
 
 }
 }
 
index 080e606..10fbceb 100644 (file)
@@ -175,13 +175,22 @@ static void SIMIX_storage_create_(smx_storage_t storage)
   SIMIX_storage_create(key, storage, NULL);
 }
 
   SIMIX_storage_create(key, storage, NULL);
 }
 
-static void (*maestro_code)(void*) = nullptr;
-static void* maestro_data = nullptr;
+static std::function<void()> maestro_code;
+
+namespace simgrid {
+namespace simix {
+
+XBT_PUBLIC(void) set_maestro(std::function<void()> code)
+{
+  maestro_code = std::move(code);
+}
+
+}
+}
 
 void SIMIX_set_maestro(void (*code)(void*), void* data)
 {
 
 void SIMIX_set_maestro(void (*code)(void*), void* data)
 {
-  maestro_code = code;
-  maestro_data = data;
+  maestro_code = std::bind(code, data);
 }
 
 /**
 }
 
 /**
@@ -230,7 +239,7 @@ void SIMIX_global_init(int *argc, char **argv)
 
     // Either create a new context with maestro or create
     // a context object with the current context mestro):
 
     // Either create a new context with maestro or create
     // a context object with the current context mestro):
-    SIMIX_maestro_create(maestro_code, maestro_data);
+    simgrid::simix::create_maestro(maestro_code);
 
     /* context exception handlers */
     __xbt_running_ctx_fetch = SIMIX_process_get_running_context;
 
     /* context exception handlers */
     __xbt_running_ctx_fetch = SIMIX_process_get_running_context;
index 65d1f6c..46007fb 100644 (file)
@@ -139,10 +139,10 @@ void SIMIX_process_empty_trash(void)
   }
 }
 
   }
 }
 
-/**
- * \brief Creates and runs the maestro process
- */
-void SIMIX_maestro_create(void (*code)(void*), void* data)
+namespace simgrid {
+namespace simix {
+
+void create_maestro(std::function<void()> code)
 {
   smx_process_t maestro = NULL;
   /* Create maestro process and intilialize it */
 {
   smx_process_t maestro = NULL;
   /* Create maestro process and intilialize it */
@@ -150,7 +150,7 @@ void SIMIX_maestro_create(void (*code)(void*), void* data)
   maestro->pid = simix_process_maxpid++;
   maestro->ppid = -1;
   maestro->name = (char*) "";
   maestro->pid = simix_process_maxpid++;
   maestro->ppid = -1;
   maestro->name = (char*) "";
-  maestro->data = data;
+  maestro->data = nullptr;
   maestro->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
   XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
 
   maestro->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
   XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
 
@@ -160,14 +160,24 @@ void SIMIX_maestro_create(void (*code)(void*), void* data)
     if (!simix_global)
       xbt_die("simix is not initialized, please call MSG_init first");
     maestro->context =
     if (!simix_global)
       xbt_die("simix is not initialized, please call MSG_init first");
     maestro->context =
-      simix_global->context_factory->create_maestro(
-        std::bind(code, data), maestro);
+      simix_global->context_factory->create_maestro(code, maestro);
   }
 
   maestro->simcall.issuer = maestro;
   simix_global->maestro_process = maestro;
 }
 
   }
 
   maestro->simcall.issuer = maestro;
   simix_global->maestro_process = maestro;
 }
 
+}
+}
+
+/**
+ * \brief Creates and runs the maestro process
+ */
+void SIMIX_maestro_create(void (*code)(void*), void* data)
+{
+  simgrid::simix::create_maestro(std::bind(code, data));
+}
+
 /**
  * \brief Stops a process.
  *
 /**
  * \brief Stops a process.
  *