arg->code, arg->data,
sg_host_get_name(arg->host),
SIMIX_timer_get_date(arg->kill_timer),
- arg->args.argc(), arg->args.argv(), arg->properties,
+ arg->properties,
arg->auto_restart);
}
XBT_DEBUG("Process %s (%s) is dead",
arg->context->stop();
}
-void* simcall_HANDLER_process_create(smx_simcall_t simcall,
- const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- double kill_time,
- int argc, char **argv,
- xbt_dict_t properties,
- 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)
-{
- simix_global->kill_process_function((smx_process_t) process);
-}
-
/**
* \brief Internal function to create a process.
*
*/
smx_process_t SIMIX_process_create(
const char *name,
- xbt_main_func_t code,
+ std::function<void()> code,
void *data,
const char *hostname,
double kill_time,
- simgrid::simix::args args,
xbt_dict_t properties,
int auto_restart,
smx_process_t parent_process)
else {
process = new simgrid::simix::Process();
- xbt_assert(((code != NULL) && (host != NULL)), "Invalid parameters");
+ xbt_assert(code && host != NULL, "Invalid parameters");
/* Process data */
process->pid = simix_process_maxpid++;
- process->name = std::string(name);
+ process->name = simgrid::xbt::string(name);
process->host = host;
process->data = data;
process->comms = xbt_fifo_new();
/* Process data for auto-restart */
process->auto_restart = auto_restart;
process->code = code;
- process->args = args;
XBT_VERB("Create context %s", process->name.c_str());
process->context = SIMIX_context_new(
- simgrid::simix::wrap_main(code, std::move(args)),
+ std::move(code),
simix_global->cleanup_process_function, process);
process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
if (kill_time > SIMIX_get_clock() && simix_global->kill_process_function) {
XBT_DEBUG("Process %s(%s) will be kill at time %f",
process->name.c_str(), sg_host_get_name(process->host), kill_time);
- process->kill_timer = SIMIX_timer_set(kill_time, kill_process, process);
+ process->kill_timer = SIMIX_timer_set(kill_time, [=]() {
+ simix_global->kill_process_function(process);
+ });
}
/* Tracing the process creation */
return process->host;
}
-xbt_main_func_t SIMIX_process_get_code(void){
- return SIMIX_process_self()->code;
-}
-
/* needs to be public and without simcall because it is called
by exceptions and logging events */
const char* SIMIX_process_self_get_name(void) {
arg.data = process->data;
arg.properties = NULL;
arg.auto_restart = process->auto_restart;
- arg.args = process->args;
//kill the old process
SIMIX_process_kill(process, issuer);
//start the new process
if (simix_global->create_process_function)
return simix_global->create_process_function(
- arg.name.c_str(), arg.code, arg.data,
+ arg.name.c_str(), std::move(arg.code), arg.data,
arg.hostname, arg.kill_time,
- arg.args,
arg.properties, arg.auto_restart,
nullptr);
else
return simcall_process_create(
- arg.name.c_str(), arg.code, arg.data,
+ arg.name.c_str(), std::move(arg.code), arg.data,
arg.hostname, arg.kill_time,
- arg.args.argc(), arg.args.to_argv(),
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, std::function<void()> code, void *data,
+ const char *hostname, double kill_time,
+ 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,
+ std::move(code), data, hostname,
+ kill_time, properties, auto_restart,
+ self);
+ });
+}
\ No newline at end of file