SIMIX_process_get_code() is a casuality of this refactoring: it does
not make sens in this design.
XBT_PUBLIC(int) SIMIX_process_has_pending_comms(smx_process_t process);
XBT_PUBLIC(void) SIMIX_process_on_exit_runall(smx_process_t process);
XBT_PUBLIC(void) SIMIX_process_on_exit(smx_process_t process, int_f_pvoid_pvoid_t fun, void *data);
XBT_PUBLIC(int) SIMIX_process_has_pending_comms(smx_process_t process);
XBT_PUBLIC(void) SIMIX_process_on_exit_runall(smx_process_t process);
XBT_PUBLIC(void) SIMIX_process_on_exit(smx_process_t process, int_f_pvoid_pvoid_t fun, void *data);
-XBT_PUBLIC(xbt_main_func_t) SIMIX_process_get_code(void);
/****************************** Communication *********************************/
XBT_PUBLIC(void) SIMIX_comm_set_copy_data_callback(void (*callback) (smx_synchro_t, void*, size_t));
/****************************** Communication *********************************/
XBT_PUBLIC(void) SIMIX_comm_set_copy_data_callback(void (*callback) (smx_synchro_t, void*, size_t));
*/
typedef smx_process_t (*smx_creation_func_t) (
/* name */ const char*,
*/
typedef smx_process_t (*smx_creation_func_t) (
/* name */ const char*,
- /* code */ xbt_main_func_t,
+ std::function<void()> code,
/* userdata */ void*,
/* hostname */ const char*,
/* kill_time */ double,
/* userdata */ void*,
/* hostname */ const char*,
/* kill_time */ double,
- simgrid::simix::args args,
/* props */ xbt_dict_t,
/* auto_restart */ int,
/* parent_process */ smx_process_t);
/* props */ xbt_dict_t,
/* auto_restart */ int,
/* parent_process */ smx_process_t);
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_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
XBT_PUBLIC(smx_process_t) simcall_process_create(const char *name,
+ std::function<void()> code,
void *data,
const char *hostname,
double kill_time,
void *data,
const char *hostname,
double kill_time,
- simgrid::simix::args args,
xbt_dict_t properties,
int auto_restart);
xbt_dict_t properties,
int auto_restart);
#ifndef METASIMGRID_PRIVATE_H
#define METASIMGRID_PRIVATE_H
#ifndef METASIMGRID_PRIVATE_H
#define METASIMGRID_PRIVATE_H
#include "simgrid/msg.h"
#include "simgrid/simix.h"
#include "src/include/surf/surf.h"
#include "simgrid/msg.h"
#include "simgrid/simix.h"
#include "src/include/surf/surf.h"
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_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,
+ std::function<void()> code, void *data,
const char *hostname, double kill_time,
const char *hostname, double kill_time,
- 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);
SG_END_DECL()
XBT_PUBLIC(msg_process_t) MSG_process_create_with_environment(
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);
+ const char *name, std::function<void()> code, void *data,
+ msg_host_t host, xbt_dict_t properties);
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "msg_private.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
#include "msg_private.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
}
/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
}
/* 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, simgrid::simix::args args, xbt_dict_t properties,
- int auto_restart, smx_process_t parent_process)
+smx_process_t MSG_process_create_from_SIMIX(
+ const char *name, std::function<void()> code, void *data, const char *hostname,
+ double kill_time, 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(
{
msg_host_t host = MSG_host_by_name(hostname);
msg_process_t p = MSG_process_create_with_environment(
- name, code, data, host, args.argc(), args.to_argv(), properties);
+ name, std::move(code), data, host, 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);
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)
{
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)
{
- msg_process_t res = MSG_process_create_with_environment(name, code, data, host,
- simgrid::simix::args(argc, argv), properties);
+ msg_process_t res = MSG_process_create_with_environment(name,
+ simgrid::simix::wrap_main(code, argc, argv), data, host,
+ properties);
for (int i = 0; i != argc; ++i)
xbt_free(argv[i]);
xbt_free(argv);
for (int i = 0; i != argc; ++i)
xbt_free(argv[i]);
xbt_free(argv);
}
msg_process_t MSG_process_create_with_environment(
}
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)
+ const char *name, std::function<void()> code, void *data,
+ msg_host_t host, 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);
/* 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(
/* 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, std::move(args), properties, 0);
+ name, std::move(code), simdata, sg_host_get_name(host), -1, properties, 0);
if (!process) {
/* Undo everything we have just changed */
if (!process) {
/* Undo everything we have just changed */
NULL,
arg->hostname,
arg->kill_time,
NULL,
arg->hostname,
arg->kill_time,
arg->properties,
arg->auto_restart,
NULL);
arg->properties,
arg->auto_restart,
NULL);
NULL,
arg->hostname,
arg->kill_time,
NULL,
arg->hostname,
arg->kill_time,
arg->properties,
arg->auto_restart);
}
arg->properties,
arg->auto_restart);
}
* The processes will only be restarted once, meaning that you will have to register the process
* again to restart the process again.
*/
* The processes will only be restarted once, meaning that you will have to register the process
* again to restart the process again.
*/
-void SIMIX_host_add_auto_restart_process(sg_host_t host,
- 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)
+void SIMIX_host_add_auto_restart_process(
+ sg_host_t host, const char *name, std::function<void()> code,
+ void* data, const char *hostname, double kill_time,
+ xbt_dict_t properties, int auto_restart)
{
if (!sg_host_simix(host)->auto_restart_processes) {
sg_host_simix(host)->auto_restart_processes = xbt_dynar_new(sizeof(smx_process_arg_t),_SIMIX_host_free_process_arg);
}
smx_process_arg_t arg = new simgrid::simix::ProcessArg();
arg->name = name;
{
if (!sg_host_simix(host)->auto_restart_processes) {
sg_host_simix(host)->auto_restart_processes = xbt_dynar_new(sizeof(smx_process_arg_t),_SIMIX_host_free_process_arg);
}
smx_process_arg_t arg = new simgrid::simix::ProcessArg();
arg->name = name;
+ arg->code = std::move(code);
arg->data = data;
arg->hostname = hostname;
arg->kill_time = kill_time;
arg->data = data;
arg->hostname = hostname;
arg->kill_time = kill_time;
- arg->args.assign(argc, argv);
arg->properties = properties;
arg->auto_restart = auto_restart;
arg->properties = properties;
arg->auto_restart = auto_restart;
NULL,
arg->hostname,
arg->kill_time,
NULL,
arg->hostname,
arg->kill_time,
arg->properties,
arg->auto_restart,
NULL);
} else {
simcall_process_create(arg->name.c_str(),
arg->properties,
arg->auto_restart,
NULL);
} else {
simcall_process_create(arg->name.c_str(),
- (xbt_main_func_t) arg->code,
NULL,
arg->hostname,
arg->kill_time,
NULL,
arg->hostname,
arg->kill_time,
arg->properties,
arg->auto_restart);
}
arg->properties,
arg->auto_restart);
}
#ifndef _SIMIX_HOST_PRIVATE_H
#define _SIMIX_HOST_PRIVATE_H
#ifndef _SIMIX_HOST_PRIVATE_H
#define _SIMIX_HOST_PRIVATE_H
#include <xbt/base.h>
#include "simgrid/simix.h"
#include <xbt/base.h>
#include "simgrid/simix.h"
XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host,
const char *name,
XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host,
const char *name,
+ std::function<void()> code,
void *data,
const char *hostname,
double kill_time,
void *data,
const char *hostname,
double kill_time,
xbt_dict_t properties,
int auto_restart);
xbt_dict_t properties,
int auto_restart);
arg->code, arg->data,
sg_host_get_name(arg->host),
SIMIX_timer_get_date(arg->kill_timer),
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->auto_restart);
}
XBT_DEBUG("Process %s (%s) is dead",
arg->auto_restart);
}
XBT_DEBUG("Process %s (%s) is dead",
-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)
+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);
+ void* res = SIMIX_process_create(
+ name, simgrid::simix::wrap_main(code, argc, argv), data, hostname,
+ kill_time, properties, auto_restart, simcall->issuer);
for (int i = 0; i != argc; ++i)
xbt_free(argv[i]);
xbt_free(argv);
for (int i = 0; i != argc; ++i)
xbt_free(argv[i]);
xbt_free(argv);
*/
smx_process_t SIMIX_process_create(
const char *name,
*/
smx_process_t SIMIX_process_create(
const char *name,
+ std::function<void()> code,
void *data,
const char *hostname,
double kill_time,
void *data,
const char *hostname,
double kill_time,
- 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)
else {
process = new simgrid::simix::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 data */
process->pid = simix_process_maxpid++;
process->name = std::string(name);
/* 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;
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, std::move(args)),
simix_global->cleanup_process_function, process);
process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
simix_global->cleanup_process_function, process);
process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
-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) {
/* 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.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);
//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(
//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.hostname, arg.kill_time,
arg.properties, arg.auto_restart,
nullptr);
else
return simcall_process_create(
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.hostname, arg.kill_time,
arg.properties, arg.auto_restart);
}
arg.properties, arg.auto_restart);
}
proc->segment_index = 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)
+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([&] {
{
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,
+ return SIMIX_process_create(name,
+ std::move(code), data, hostname,
+ kill_time, properties, auto_restart,
self);
});
}
\ No newline at end of file
self);
});
}
\ No newline at end of file
#ifndef _SIMIX_PROCESS_PRIVATE_H
#define _SIMIX_PROCESS_PRIVATE_H
#ifndef _SIMIX_PROCESS_PRIVATE_H
#define _SIMIX_PROCESS_PRIVATE_H
#include <string>
#include <xbt/base.h>
#include <string>
#include <xbt/base.h>
class ProcessArg {
public:
std::string name;
class ProcessArg {
public:
std::string name;
- xbt_main_func_t code = nullptr;
- simgrid::simix::args args;
+ std::function<void()> code;
void *data = nullptr;
const char *hostname = nullptr;
double kill_time = 0.0;
void *data = nullptr;
const char *hostname = nullptr;
double kill_time = 0.0;
void *data = nullptr; /* kept for compatibility, it should be replaced with moddata */
xbt_dynar_t on_exit = nullptr; /* list of functions executed when the process dies */
void *data = nullptr; /* kept for compatibility, it should be replaced with moddata */
xbt_dynar_t on_exit = nullptr; /* list of functions executed when the process dies */
- xbt_main_func_t code = nullptr;
- simgrid::simix::args args;
+ std::function<void()> code;
smx_timer_t kill_timer = nullptr;
int segment_index = 0; /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
};
smx_timer_t kill_timer = nullptr;
int segment_index = 0; /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
};
XBT_PRIVATE smx_process_t SIMIX_process_create(
const char *name,
XBT_PRIVATE smx_process_t SIMIX_process_create(
const char *name,
+ std::function<void()> code,
void *data,
const char *hostname,
double kill_time,
void *data,
const char *hostname,
double kill_time,
- 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);
double kill_time = process->kill_time;
int auto_restart = process->on_failure == SURF_PROCESS_ON_FAILURE_DIE ? 0 : 1;
double kill_time = process->kill_time;
int auto_restart = process->on_failure == SURF_PROCESS_ON_FAILURE_DIE ? 0 : 1;
+ std::function<void()> code = simgrid::simix::wrap_main(parse_code, process->argc, process->argv);
+
smx_process_arg_t arg = NULL;
smx_process_t process_created = NULL;
arg = new simgrid::simix::ProcessArg();
arg->name = std::string(process->argv[0]);
smx_process_arg_t arg = NULL;
smx_process_t process_created = NULL;
arg = new simgrid::simix::ProcessArg();
arg->name = std::string(process->argv[0]);
- arg->code = parse_code;
arg->data = NULL;
arg->hostname = sg_host_get_name(host);
arg->data = NULL;
arg->hostname = sg_host_get_name(host);
- arg->args.assign(process->argc, process->argv);
arg->kill_time = kill_time;
arg->properties = current_property_set;
if (!sg_host_simix(host)->boot_processes)
arg->kill_time = kill_time;
arg->properties = current_property_set;
if (!sg_host_simix(host)->boot_processes)
xbt_dynar_push_as(sg_host_simix(host)->boot_processes,smx_process_arg_t,arg);
if (start_time > SIMIX_get_clock()) {
xbt_dynar_push_as(sg_host_simix(host)->boot_processes,smx_process_arg_t,arg);
if (start_time > SIMIX_get_clock()) {
arg = new simgrid::simix::ProcessArg();
arg->name = std::string(process->argv[0]);
arg = new simgrid::simix::ProcessArg();
arg->name = std::string(process->argv[0]);
- arg->code = parse_code;
+ arg->code = std::move(code);
arg->data = NULL;
arg->hostname = sg_host_get_name(host);
arg->data = NULL;
arg->hostname = sg_host_get_name(host);
- arg->args.assign(process->argc, process->argv);
arg->kill_time = kill_time;
arg->properties = current_property_set;
arg->kill_time = kill_time;
arg->properties = current_property_set;
smx_process_arg_t arg = static_cast<smx_process_arg_t>(p);
simix_global->create_process_function(
arg->name.c_str(),
smx_process_arg_t arg = static_cast<smx_process_arg_t>(p);
simix_global->create_process_function(
arg->name.c_str(),
arg->data,
arg->hostname,
arg->kill_time,
arg->data,
arg->hostname,
arg->kill_time,
arg->properties,
arg->auto_restart,
NULL);
arg->properties,
arg->auto_restart,
NULL);
if (simix_global->create_process_function)
process_created = simix_global->create_process_function(
if (simix_global->create_process_function)
process_created = simix_global->create_process_function(
- arg->name.c_str(),
- parse_code,
- NULL,
- sg_host_get_name(host),
- kill_time,
- arg->args,
- current_property_set,
- auto_restart, NULL);
+ arg->name.c_str(), std::move(code), NULL,
+ sg_host_get_name(host), kill_time,
+ current_property_set, auto_restart, NULL);
else
process_created = simcall_process_create(
else
process_created = simcall_process_create(
- arg->name.c_str(), parse_code, NULL, sg_host_get_name(host), kill_time,
- arg->args, current_property_set,auto_restart);
+ arg->name.c_str(), std::move(code), NULL, sg_host_get_name(host), kill_time,
+ 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) {