The main missing bit is the simcall.
} 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
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 */
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) {
- auto arg = std::make_shared<simgrid::simix::args>(argc, argv);
return [=]() {
- code(arg->argc(), arg->argv());
+ code(args->argc(), args->argv());
};
}
- // TODO, we should free argv
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;
}
}
+/*
+ * 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
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 */
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);
/* 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);
- 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);
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->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;
* 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;
}
NULL,
arg->hostname,
arg->kill_time,
- arg->args.argc(), arg->args.to_argv(),
+ arg->args,
arg->properties,
arg->auto_restart,
NULL);
NULL,
arg->hostname,
arg->kill_time,
- arg->args.argc(), arg->args.to_argv(),
+ arg->args,
arg->properties,
arg->auto_restart,
NULL);
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);
+ for (int i = 0; i != argc; ++i)
+ xbt_free(argv[i]);
+ xbt_free(argv);
+ return res;
}
static void kill_process(void* process)
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_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);
- for (i = 0; i < argc; i++)
- xbt_free(argv[i]);
- xbt_free(argv);
+ return nullptr;
}
else {
process = new simgrid::simix::Process();
/* 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(
- simgrid::simix::wrap_main(code, argc, argv),
+ simgrid::simix::wrap_main(code, std::move(args)),
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);
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
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);
arg->data,
arg->hostname,
arg->kill_time,
- arg->args.argc(), arg->args.to_argv(),
+ std::move(arg->args),
arg->properties,
arg->auto_restart,
NULL);
NULL,
sg_host_get_name(host),
kill_time,
- arg->args.argc(), arg->args.to_argv(),
+ arg->args,
current_property_set,
auto_restart, NULL);
else