Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Create a (fake) simcall for creating a process directly from a simgrid::simix...
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 20 May 2016 11:50:17 +0000 (13:50 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 23 May 2016 07:05:21 +0000 (09:05 +0200)
include/simgrid/simix.hpp
src/msg/msg_private.h
src/msg/msg_process.cpp
src/simix/smx_host.cpp
src/simix/smx_process.cpp
src/surf/sg_platf.cpp

index 9f73275..cf51596 100644 (file)
@@ -308,4 +308,13 @@ typedef smx_process_t (*smx_creation_func_t) (
 extern "C"
 XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
 
 extern "C"
 XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
 
+XBT_PUBLIC(smx_process_t) simcall_process_create(const char *name,
+                                          xbt_main_func_t code,
+                                          void *data,
+                                          const char *hostname,
+                                          double kill_time,
+                                          simgrid::simix::args args,
+                                          xbt_dict_t properties,
+                                          int auto_restart);
+
 #endif
 #endif
index 0e976d8..0d004f7 100644 (file)
@@ -189,4 +189,10 @@ XBT_PRIVATE void TRACE_msg_vm_restore(msg_vm_t vm);
 XBT_PRIVATE void TRACE_msg_vm_end(msg_vm_t vm);
 
 SG_END_DECL()
 XBT_PRIVATE void TRACE_msg_vm_end(msg_vm_t vm);
 
 SG_END_DECL()
+
+XBT_PUBLIC(msg_process_t) MSG_process_create_with_environment(
+  const char *name, xbt_main_func_t code, void *data,
+  msg_host_t host, simgrid::simix::args args,
+  xbt_dict_t properties);
+
 #endif
 #endif
index e871197..6ca8e3a 100644 (file)
@@ -126,7 +126,20 @@ msg_process_t MSG_process_create_with_arguments(const char *name, xbt_main_func_
  * \return The new corresponding object.
  */
 msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_func_t code, void *data, msg_host_t host,
  * \return The new corresponding object.
  */
 msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_func_t code, void *data, msg_host_t host,
-                                                int argc, char **argv, xbt_dict_t properties)
+                                                  int argc, char **argv, xbt_dict_t properties)
+{
+  msg_process_t res = MSG_process_create_with_environment(name, code, data, host,
+    simgrid::simix::args(argc, argv), properties);
+  for (int i = 0; i != argc; ++i)
+    xbt_free(argv[i]);
+  xbt_free(argv);
+  return res;
+}
+
+msg_process_t MSG_process_create_with_environment(
+  const char *name, xbt_main_func_t code, void *data,
+  msg_host_t host, simgrid::simix::args args,
+  xbt_dict_t properties)
 {
   xbt_assert(code != NULL && host != NULL, "Invalid parameters: host and code params must not be NULL");
   simdata_process_t simdata = xbt_new0(s_simdata_process_t, 1);
 {
   xbt_assert(code != NULL && host != NULL, "Invalid parameters: host and code params must not be NULL");
   simdata_process_t simdata = xbt_new0(s_simdata_process_t, 1);
@@ -141,7 +154,8 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun
 
   /* Let's create the process: SIMIX may decide to start it right now,
    * even before returning the flow control to us */
 
   /* Let's create the process: SIMIX may decide to start it right now,
    * even before returning the flow control to us */
-  process = simcall_process_create(name, code, simdata, sg_host_get_name(host), -1, argc, argv, properties,0);
+  process = simcall_process_create(
+    name, code, simdata, sg_host_get_name(host), -1, std::move(args), properties, 0);
 
   if (!process) {
     /* Undo everything we have just changed */
 
   if (!process) {
     /* Undo everything we have just changed */
index 32a9a3f..d4684dd 100644 (file)
@@ -67,7 +67,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);
       }
                                arg->properties,
                                arg->auto_restart);
       }
@@ -226,7 +226,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);
     }
                              arg->properties,
                              arg->auto_restart);
     }
index b6c816f..f77724d 100644 (file)
@@ -1019,10 +1019,29 @@ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer)
     return simcall_process_create(
       arg.name.c_str(), arg.code, arg.data,
       arg.hostname, arg.kill_time,
     return simcall_process_create(
       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);
 }
 
 void SIMIX_segment_index_set(smx_process_t proc, int index){
   proc->segment_index = index;
 }
       arg.properties, arg.auto_restart);
 }
 
 void SIMIX_segment_index_set(smx_process_t proc, int index){
   proc->segment_index = index;
 }
+
+smx_process_t simcall_process_create(const char *name,
+                                          xbt_main_func_t code,
+                                          void *data,
+                                          const char *hostname,
+                                          double kill_time,
+                                          simgrid::simix::args args,
+                                          xbt_dict_t properties,
+                                          int auto_restart)
+{
+  if (name == nullptr)
+    name = "";
+  smx_process_t self = SIMIX_process_self();
+  return simgrid::simix::kernel([&] {
+    return SIMIX_process_create(name, code, data, hostname,
+          kill_time, std::move(args), properties, auto_restart,
+          self);
+  });
+}
\ No newline at end of file
index e1259d7..35cd58e 100644 (file)
@@ -631,7 +631,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
     else
       process_created = simcall_process_create(
           arg->name.c_str(), parse_code, NULL, sg_host_get_name(host), kill_time,
     else
       process_created = simcall_process_create(
           arg->name.c_str(), parse_code, NULL, sg_host_get_name(host), kill_time,
-          arg->args.argc(), arg->args.to_argv(), current_property_set,auto_restart);
+          arg->args, current_property_set,auto_restart);
 
     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
     if (!process_created) {
 
     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
     if (!process_created) {