X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5c037db836667c8408d94daf61b893dd1efbabca..d919680dd6d792fccc5cab4ace6fbe93974919cd:/src/simix/smx_process.cpp diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index b6c816f9d7..724353594a 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -194,7 +194,7 @@ void SIMIX_process_stop(smx_process_t arg) { 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", @@ -202,31 +202,6 @@ void SIMIX_process_stop(smx_process_t arg) { 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. * @@ -238,11 +213,10 @@ static void kill_process(void* process) */ smx_process_t SIMIX_process_create( const char *name, - xbt_main_func_t code, + std::function 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) @@ -260,10 +234,10 @@ smx_process_t SIMIX_process_create( 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(); @@ -291,11 +265,10 @@ smx_process_t SIMIX_process_create( /* 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)); @@ -322,7 +295,9 @@ smx_process_t SIMIX_process_create( 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 */ @@ -728,10 +703,6 @@ sg_host_t SIMIX_process_get_host(smx_process_t process) 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) { @@ -1002,7 +973,6 @@ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer) 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); @@ -1010,19 +980,33 @@ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t 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 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