Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Use simgrid::simix::args in MSG
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 20 May 2016 11:39:33 +0000 (13:39 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 23 May 2016 07:05:21 +0000 (09:05 +0200)
The main missing bit is the simcall.

include/simgrid/simix.h
include/simgrid/simix.hpp
src/msg/msg_private.h
src/msg/msg_process.cpp
src/simix/smx_global.cpp
src/simix/smx_host.cpp
src/simix/smx_process.cpp
src/simix/smx_process_private.h
src/surf/sg_platf.cpp

index 8f31a42..f0de3ed 100644 (file)
@@ -111,31 +111,6 @@ typedef enum {
 } smx_process_exit_status_t;
 /** @} */
 
 } smx_process_exit_status_t;
 /** @} */
 
-
-/*
- * Type of function that creates a process.
- * The function must accept the following parameters:
- * void* process: the process created will be stored there
- * const char *name: a name for the object. It is for user-level information and can be NULL
- * xbt_main_func_t code: is a function describing the behavior of the process
- * void *data: data a pointer to any data one may want to attach to the new object.
- * sg_host_t host: the location where the new process is executed
- * int argc, char **argv: parameters passed to code
- * xbt_dict_t pros: properties
- */
-typedef smx_process_t (*smx_creation_func_t) (
-                                      /* name */ const char*,
-                                      /* code */ xbt_main_func_t,
-                                      /* userdata */ void*,
-                                      /* hostname */ const char*,
-                                      /* kill_time */ double,
-                                      /* argc */ int,
-                                      /* argv */ char**,
-                                      /* props */ xbt_dict_t,
-                                      /* auto_restart */ int,
-                                      /* parent_process */ smx_process_t);
-
-
 /******************************* Networking ***********************************/
 /**
  * \ingroup simix_mbox_management
 /******************************* Networking ***********************************/
 /**
  * \ingroup simix_mbox_management
@@ -178,7 +153,6 @@ XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv);
 XBT_PUBLIC(void) SIMIX_set_maestro(void (*code)(void*), void* data);
 
 XBT_PUBLIC(void) SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t function);
 XBT_PUBLIC(void) SIMIX_set_maestro(void (*code)(void*), void* data);
 
 XBT_PUBLIC(void) SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t function);
-XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
 XBT_PUBLIC(void) SIMIX_function_register_process_kill(void_pfn_smxprocess_t function);
 
 /* Simulation execution */
 XBT_PUBLIC(void) SIMIX_function_register_process_kill(void_pfn_smxprocess_t function);
 
 /* Simulation execution */
index c28bf8b..9f73275 100644 (file)
@@ -157,19 +157,32 @@ public:
   char* operator[](std::size_t i) { return argv_[i]; }
 };
 
   char* operator[](std::size_t i) { return argv_[i]; }
 };
 
-inline
-std::function<void()> wrap_main(xbt_main_func_t code, int argc, const char*const* argv)
+inline std::function<void()> wrap_main(
+  xbt_main_func_t code,  std::shared_ptr<simgrid::simix::args> args)
 {
   if (code) {
 {
   if (code) {
-    auto arg = std::make_shared<simgrid::simix::args>(argc, argv);
     return [=]() {
     return [=]() {
-      code(arg->argc(), arg->argv());
+      code(args->argc(), args->argv());
     };
   }
     };
   }
-  // TODO, we should free argv
   else return std::function<void()>();
 }
 
   else return std::function<void()>();
 }
 
+inline
+std::function<void()> wrap_main(xbt_main_func_t code, simgrid::simix::args args)
+{
+  if (code)
+    return wrap_main(code, std::unique_ptr<simgrid::simix::args>(
+      new simgrid::simix::args(std::move(args))));
+  else return std::function<void()>();
+}
+
+inline
+std::function<void()> wrap_main(xbt_main_func_t code, int argc, const char*const* argv)
+{
+  return wrap_main(code, simgrid::simix::args(argc, argv));
+}
+
 class Context;
 class ContextFactory;
 
 class Context;
 class ContextFactory;
 
@@ -270,4 +283,29 @@ XBT_PUBLIC(void) create_maestro(std::function<void()> code);
 }
 }
 
 }
 }
 
+/*
+ * Type of function that creates a process.
+ * The function must accept the following parameters:
+ * void* process: the process created will be stored there
+ * const char *name: a name for the object. It is for user-level information and can be NULL
+ * xbt_main_func_t code: is a function describing the behavior of the process
+ * void *data: data a pointer to any data one may want to attach to the new object.
+ * sg_host_t host: the location where the new process is executed
+ * int argc, char **argv: parameters passed to code
+ * xbt_dict_t pros: properties
+ */
+typedef smx_process_t (*smx_creation_func_t) (
+                                      /* name */ const char*,
+                                      /* code */ xbt_main_func_t,
+                                      /* userdata */ void*,
+                                      /* hostname */ const char*,
+                                      /* kill_time */ double,
+                                      simgrid::simix::args args,
+                                      /* props */ xbt_dict_t,
+                                      /* auto_restart */ int,
+                                      /* parent_process */ smx_process_t);
+
+extern "C"
+XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
+
 #endif
 #endif
index f39cdd0..0e976d8 100644 (file)
@@ -79,8 +79,6 @@ typedef struct simdata_process {
   msg_host_t put_host;            /* used for debugging purposes */
   smx_synchro_t waiting_action;
   msg_task_t waiting_task;
   msg_host_t put_host;            /* used for debugging purposes */
   smx_synchro_t waiting_action;
   msg_task_t waiting_task;
-  char **argv;                  /* arguments table if any */
-  int argc;                     /* arguments number if any */
   msg_error_t last_errno;       /* the last value returned by a MSG_function */
 
   void* data;                   /* user data */
   msg_error_t last_errno;       /* the last value returned by a MSG_function */
 
   void* data;                   /* user data */
@@ -143,7 +141,7 @@ XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc);
 XBT_PRIVATE smx_process_t MSG_process_create_from_SIMIX(const char *name,
                                    xbt_main_func_t code, void *data,
                                    const char *hostname, double kill_time,
 XBT_PRIVATE smx_process_t MSG_process_create_from_SIMIX(const char *name,
                                    xbt_main_func_t code, void *data,
                                    const char *hostname, double kill_time,
-                                   int argc, char **argv,
+                                   simgrid::simix::args args,
                                    xbt_dict_t properties, int auto_restart,
                                    smx_process_t parent_process);
 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_synchro_t comm, void* buff, size_t buff_size);
                                    xbt_dict_t properties, int auto_restart,
                                    smx_process_t parent_process);
 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_synchro_t comm, void* buff, size_t buff_size);
index 1b4599d..e871197 100644 (file)
@@ -53,11 +53,12 @@ void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc)
 
 /* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
 smx_process_t MSG_process_create_from_SIMIX(const char *name, xbt_main_func_t code, void *data, const char *hostname,
 
 /* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
 smx_process_t MSG_process_create_from_SIMIX(const char *name, xbt_main_func_t code, void *data, const char *hostname,
-                                            double kill_time, int argc, char **argv, xbt_dict_t properties,
+                                            double kill_time, simgrid::simix::args args, xbt_dict_t properties,
                                             int auto_restart, smx_process_t parent_process)
 {
   msg_host_t host = MSG_host_by_name(hostname);
                                             int auto_restart, smx_process_t parent_process)
 {
   msg_host_t host = MSG_host_by_name(hostname);
-  msg_process_t p = MSG_process_create_with_environment(name, code, data, host, argc, argv, properties);
+  msg_process_t p = MSG_process_create_with_environment(
+    name, code, data, host, args.argc(), args.to_argv(), properties);
   if (p) {
     MSG_process_set_kill_time(p,kill_time);
     MSG_process_auto_restart_set(p,auto_restart);
   if (p) {
     MSG_process_set_kill_time(p,kill_time);
     MSG_process_auto_restart_set(p,auto_restart);
@@ -135,8 +136,6 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun
   simdata->waiting_action = NULL;
   simdata->waiting_task = NULL;
   simdata->m_host = host;
   simdata->waiting_action = NULL;
   simdata->waiting_task = NULL;
   simdata->m_host = host;
-  simdata->argc = argc;
-  simdata->argv = argv;
   simdata->data = data;
   simdata->last_errno = MSG_OK;
 
   simdata->data = data;
   simdata->last_errno = MSG_OK;
 
@@ -178,8 +177,6 @@ msg_process_t MSG_process_attach(const char *name, void *data, msg_host_t host,
   simdata->waiting_action = NULL;
   simdata->waiting_task = NULL;
   simdata->m_host = host;
   simdata->waiting_action = NULL;
   simdata->waiting_task = NULL;
   simdata->m_host = host;
-  simdata->argc = 0;
-  simdata->argv = NULL;
   simdata->data = data;
   simdata->last_errno = MSG_OK;
 
   simdata->data = data;
   simdata->last_errno = MSG_OK;
 
index 9771e89..4e753fe 100644 (file)
@@ -549,8 +549,7 @@ double SIMIX_timer_get_date(smx_timer_t timer) {
  * to call SIMIX_process_create().
  * \param function create process function
  */
  * to call SIMIX_process_create().
  * \param function create process function
  */
-void SIMIX_function_register_process_create(smx_creation_func_t
-                                                       function)
+void SIMIX_function_register_process_create(smx_creation_func_t function)
 {
   simix_global->create_process_function = function;
 }
 {
   simix_global->create_process_function = function;
 }
index 1fdde27..32a9a3f 100644 (file)
@@ -57,7 +57,7 @@ void SIMIX_host_on(sg_host_t h)
                                               NULL,
                                               arg->hostname,
                                               arg->kill_time,
                                               NULL,
                                               arg->hostname,
                                               arg->kill_time,
-                                              arg->args.argc(), arg->args.to_argv(),
+                                              arg->args,
                                               arg->properties,
                                               arg->auto_restart,
                                               NULL);
                                               arg->properties,
                                               arg->auto_restart,
                                               NULL);
@@ -216,7 +216,7 @@ void SIMIX_host_autorestart(sg_host_t host)
                                             NULL,
                                             arg->hostname,
                                             arg->kill_time,
                                             NULL,
                                             arg->hostname,
                                             arg->kill_time,
-                                            arg->args.argc(), arg->args.to_argv(),
+                                            arg->args,
                                             arg->properties,
                                             arg->auto_restart,
                                             NULL);
                                             arg->properties,
                                             arg->auto_restart,
                                             NULL);
index 76ec52f..b6c816f 100644 (file)
@@ -210,10 +210,16 @@ void* simcall_HANDLER_process_create(smx_simcall_t simcall,
                           double kill_time,
                           int argc, char **argv,
                           xbt_dict_t properties,
                           double kill_time,
                           int argc, char **argv,
                           xbt_dict_t properties,
-                          int auto_restart){
-  return (void*)SIMIX_process_create(name, code, data, hostname,
-                       kill_time, argc, argv, properties, auto_restart,
+                          int auto_restart)
+{
+  simgrid::simix::args args(argc, argv);
+  void* res = SIMIX_process_create(name, code, data, hostname,
+                       kill_time, std::move(args), properties, auto_restart,
                        simcall->issuer);
                        simcall->issuer);
+  for (int i = 0; i != argc; ++i)
+    xbt_free(argv[i]);
+  xbt_free(argv);
+  return res;
 }
 
 static void kill_process(void* process)
 }
 
 static void kill_process(void* process)
@@ -236,7 +242,7 @@ smx_process_t SIMIX_process_create(
                           void *data,
                           const char *hostname,
                           double kill_time,
                           void *data,
                           const char *hostname,
                           double kill_time,
-                          int argc, char **argv,
+                          simgrid::simix::args args,
                           xbt_dict_t properties,
                           int auto_restart,
                           smx_process_t parent_process)
                           xbt_dict_t properties,
                           int auto_restart,
                           smx_process_t parent_process)
@@ -247,12 +253,9 @@ smx_process_t SIMIX_process_create(
   XBT_DEBUG("Start process %s on host '%s'", name, hostname);
 
   if (host->isOff()) {
   XBT_DEBUG("Start process %s on host '%s'", name, hostname);
 
   if (host->isOff()) {
-    int i;
     XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
           hostname);
     XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
           hostname);
-    for (i = 0; i < argc; i++)
-      xbt_free(argv[i]);
-    xbt_free(argv);
+    return nullptr;
   }
   else {
     process = new simgrid::simix::Process();
   }
   else {
     process = new simgrid::simix::Process();
@@ -288,17 +291,13 @@ smx_process_t SIMIX_process_create(
     /* Process data for auto-restart */
     process->auto_restart = auto_restart;
     process->code = code;
     /* Process data for auto-restart */
     process->auto_restart = auto_restart;
     process->code = code;
-    process->args.assign(argc, argv);
+    process->args = args;
 
     XBT_VERB("Create context %s", process->name.c_str());
     process->context = SIMIX_context_new(
 
     XBT_VERB("Create context %s", process->name.c_str());
     process->context = SIMIX_context_new(
-      simgrid::simix::wrap_main(code, argc, argv),
+      simgrid::simix::wrap_main(code, std::move(args)),
       simix_global->cleanup_process_function, process);
 
       simix_global->cleanup_process_function, process);
 
-    for (int i = 0; i < argc; i++)
-      free(argv[i]);
-    free(argv);
-
     process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
     XBT_RUNNING_CTX_INITIALIZE(process->running_ctx);
 
     process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
     XBT_RUNNING_CTX_INITIALIZE(process->running_ctx);
 
@@ -1013,7 +1012,7 @@ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer)
     return simix_global->create_process_function(
       arg.name.c_str(), arg.code, arg.data,
       arg.hostname, arg.kill_time,
     return simix_global->create_process_function(
       arg.name.c_str(), arg.code, arg.data,
       arg.hostname, arg.kill_time,
-      arg.args.argc(), arg.args.to_argv(),
+      arg.args,
       arg.properties, arg.auto_restart,
       nullptr);
   else
       arg.properties, arg.auto_restart,
       nullptr);
   else
index 204eb3d..3a3db8d 100644 (file)
@@ -86,7 +86,7 @@ XBT_PRIVATE smx_process_t SIMIX_process_create(
                           void *data,
                           const char *hostname,
                           double kill_time,
                           void *data,
                           const char *hostname,
                           double kill_time,
-                          int argc, char **argv,
+                          simgrid::simix::args args,
                           xbt_dict_t properties,
                           int auto_restart,
                           smx_process_t parent_process);
                           xbt_dict_t properties,
                           int auto_restart,
                           smx_process_t parent_process);
index 8ccd61c..e1259d7 100644 (file)
@@ -608,7 +608,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
                                             arg->data,
                                             arg->hostname,
                                             arg->kill_time,
                                             arg->data,
                                             arg->hostname,
                                             arg->kill_time,
-                                            arg->args.argc(), arg->args.to_argv(),
+                                            std::move(arg->args),
                                             arg->properties,
                                             arg->auto_restart,
                                             NULL);
                                             arg->properties,
                                             arg->auto_restart,
                                             NULL);
@@ -625,7 +625,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
                                             NULL,
                                             sg_host_get_name(host),
                                             kill_time,
                                             NULL,
                                             sg_host_get_name(host),
                                             kill_time,
-                                            arg->args.argc(), arg->args.to_argv(),
+                                            arg->args,
                                             current_property_set,
                                             auto_restart, NULL);
     else
                                             current_property_set,
                                             auto_restart, NULL);
     else