/* User create and kill process, the function must accept the folling 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 agent
* void *data: data a pointer to any data one may want to attach to the new object.
* int argc, char **argv: parameters passed to code
*
* */
-typedef void *(*smx_creation_func_t) ( /*name */ const char *,
+typedef void (*smx_creation_func_t) ( /* process */ void *,
+ /*name */ const char *,
/*code */ xbt_main_func_t,
/*userdata */ void *,
/*hostname */ char *,
/**************************** Process Requests ********************************/
/* Constructor and Destructor */
-XBT_PUBLIC(smx_process_t) SIMIX_req_process_create(const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- int argc, char **argv,
- xbt_dict_t properties);
+XBT_PUBLIC(void) SIMIX_req_process_create(smx_process_t *process,
+ const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ int argc, char **argv,
+ xbt_dict_t properties);
XBT_PUBLIC(void) SIMIX_req_process_kill(smx_process_t process);
xbt_dict_t properties)
{
- SIMIX_req_process_create(name, code, NULL,
+ smx_process_t process;
+ SIMIX_req_process_create(&process, name, code, NULL,
gras_os_myname(), argc, argv, properties);
}
}
/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
-void *_MSG_process_create_from_SIMIX(const char *name,
- xbt_main_func_t code, void *data,
- char *hostname, int argc, char **argv,
- xbt_dict_t properties)
+void _MSG_process_create_from_SIMIX(void* process, const char *name,
+ xbt_main_func_t code, void *data,
+ char *hostname, int argc, char **argv,
+ xbt_dict_t properties)
{
m_host_t host = MSG_get_host_by_name(hostname);
- return (void *) MSG_process_create_with_environment(name, code, data,
+ m_process_t p = MSG_process_create_with_environment(name, code, data,
host, argc, argv,
properties);
+ *((m_process_t*) process) = p;
}
/** \ingroup m_process_management
process->data = data;
xbt_fifo_unshift(msg_global->process_list, process);
- /* Let's create the process (SIMIX may decide to start it right now) */
- simdata->s_process = SIMIX_req_process_create(name, code, (void *) process, host->name,
- argc, argv, properties);
+ /* Let's create the process: SIMIX may decide to start it right now,
+ * even before returning the flow control to us */
+ SIMIX_req_process_create(&simdata->s_process, name, code, (void *) process, host->name,
+ argc, argv, properties);
if (!simdata->s_process) {
/* Undo everything we have just changed */
void __MSG_display_process_status(void);
void __MSG_process_cleanup(smx_process_t smx_proc);
-void *_MSG_process_create_from_SIMIX(const char *name,
- xbt_main_func_t code, void *data,
- char *hostname, int argc,
- char **argv, xbt_dict_t properties);
+void _MSG_process_create_from_SIMIX(void *process, const char *name,
+ xbt_main_func_t code, void *data,
+ char *hostname, int argc,
+ char **argv, xbt_dict_t properties);
void _MSG_process_kill_from_SIMIX(void *p);
void _MSG_action_init(void);
xbt_dict_t properties;
} s_smx_process_arg_t, *smx_process_arg_t;
-smx_process_t SIMIX_process_create(const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- int argc, char **argv,
- xbt_dict_t properties);
+void SIMIX_process_create(smx_process_t *process,
+ const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ int argc, char **argv,
+ xbt_dict_t properties);
void SIMIX_process_kill(smx_process_t process, smx_process_t killer);
void SIMIX_process_killall(void);
smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args);
} host_execution_wait;
struct {
+ smx_process_t *process;
const char *name;
xbt_main_func_t code;
void *data;
int argc;
char **argv;
xbt_dict_t properties;
- smx_process_t result;
} process_create;
struct {
static void parse_process_finalize(void)
{
smx_process_arg_t arg = NULL;
- void *process = NULL;
+ smx_process_t process = NULL;
if (start_time > SIMIX_get_clock()) {
arg = xbt_new0(s_smx_process_arg_t, 1);
arg->name = parse_argv[0];
DEBUG2("Starting Process %s(%s) right now", parse_argv[0], parse_host);
if (simix_global->create_process_function)
- process =
- (*simix_global->create_process_function) (parse_argv[0],
- parse_code, NULL,
- parse_host, parse_argc,
- parse_argv,
- /*the props */
- current_property_set);
+ (*simix_global->create_process_function) (&process,
+ parse_argv[0],
+ parse_code, NULL,
+ parse_host, parse_argc,
+ parse_argv,
+ current_property_set);
else
- process = SIMIX_req_process_create(parse_argv[0], parse_code, NULL, parse_host, parse_argc, parse_argv, /*the props */
- current_property_set);
+ SIMIX_req_process_create(&process, parse_argv[0], parse_code, NULL, parse_host, parse_argc, parse_argv,
+ current_property_set);
/* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
if (!process) {
xbt_free(parse_host);
smx_process_t process;
if (simix_global->create_process_function) {
- process = simix_global->create_process_function(args->name,
+ simix_global->create_process_function(
+ &process,
+ args->name,
args->code,
args->data,
args->hostname,
args->properties);
}
else {
- process = SIMIX_process_create(args->name,
+ SIMIX_process_create(
+ &process,
+ args->name,
args->code,
args->data,
args->hostname,
*
* \return the process created
*/
-smx_process_t SIMIX_process_create(const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- int argc, char **argv,
- xbt_dict_t properties) {
-
- smx_process_t process = NULL;
+void SIMIX_process_create(smx_process_t *process,
+ const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ int argc, char **argv,
+ xbt_dict_t properties) {
+
+ *process = NULL;
smx_host_t host = SIMIX_host_get_by_name(hostname);
DEBUG2("Start process %s on host %s", name, hostname);
hostname);
}
else {
- process = xbt_new0(s_smx_process_t, 1);
+ *process = xbt_new0(s_smx_process_t, 1);
xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters");
/* Process data */
- process->pid = simix_process_maxpid++;
- process->name = xbt_strdup(name);
- process->smx_host = host;
- process->data = data;
+ (*process)->pid = simix_process_maxpid++;
+ (*process)->name = xbt_strdup(name);
+ (*process)->smx_host = host;
+ (*process)->data = data;
- VERB1("Create context %s", process->name);
- process->context = SIMIX_context_new(code, argc, argv,
- simix_global->cleanup_process_function, process);
+ VERB1("Create context %s", (*process)->name);
+ (*process)->context = SIMIX_context_new(code, argc, argv,
+ simix_global->cleanup_process_function, *process);
- process->running_ctx = xbt_new(xbt_running_ctx_t, 1);
- XBT_RUNNING_CTX_INITIALIZE(process->running_ctx);
+ (*process)->running_ctx = xbt_new(xbt_running_ctx_t, 1);
+ XBT_RUNNING_CTX_INITIALIZE((*process)->running_ctx);
/* Add properties */
- process->properties = properties;
+ (*process)->properties = properties;
/* Add the process to it's host process list */
- xbt_swag_insert(process, host->process_list);
+ xbt_swag_insert(*process, host->process_list);
- DEBUG1("Start context '%s'", process->name);
+ DEBUG1("Start context '%s'", (*process)->name);
/* Now insert it in the global process list and in the process to run list */
- xbt_swag_insert(process, simix_global->process_list);
- DEBUG2("Inserting %s(%s) in the to_run list", process->name, host->name);
- xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
+ xbt_swag_insert(*process, simix_global->process_list);
+ DEBUG2("Inserting %s(%s) in the to_run list", (*process)->name, host->name);
+ xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, *process);
}
-
- return process;
}
/**
void SIMIX_process_suspend(smx_process_t process, smx_process_t issuer)
{
- xbt_assert0(process, "Invalid parameters");
-
process->suspended = 1;
/* If we are suspending another process, and it is waiting on an action,
break;
case REQ_PROCESS_CREATE:
- req->process_create.result = SIMIX_process_create(
+ SIMIX_process_create(
+ req->process_create.process,
req->process_create.name,
req->process_create.code,
req->process_create.data,
/**
* \brief Creates and runs a new SIMIX process.
*
- * The structure and the corresponding threada are created and put in the list of ready processes.
+ * The structure and the corresponding thread are created and put in the list of ready processes.
*
+ * \param process the process created will be stored in this pointer
* \param name a name for the process. It is for user-level information and can be NULL.
* \param code the main function of the process
* \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be NULL.
* \param argc first argument passed to \a code
* \param argv second argument passed to \a code
* \param properties the properties of the process
- * \return The new process
*/
-smx_process_t SIMIX_req_process_create(const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- int argc, char **argv,
- xbt_dict_t properties)
+void SIMIX_req_process_create(smx_process_t *process, const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ int argc, char **argv,
+ xbt_dict_t properties)
{
smx_req_t req = SIMIX_req_mine();
req->call = REQ_PROCESS_CREATE;
+ req->process_create.process = process;
req->process_create.name = name;
req->process_create.code = code;
req->process_create.data = data;
req->process_create.argv = argv;
req->process_create.properties = properties;
SIMIX_request_push();
- return req->process_create.result;
}
/** \brief Kills a SIMIX process.
*/
void SIMIX_req_process_suspend(smx_process_t process)
{
+ xbt_assert0(process, "Invalid parameters");
+
smx_req_t req = SIMIX_req_mine();
req->call = REQ_PROCESS_SUSPEND;
res->code = code;
res->father_data = SIMIX_process_self_get_data();
/* char*name = bprintf("%s#%p",SIMIX_process_self_get_name(), param); */
- res->s_process = SIMIX_req_process_create(name,
- xbt_thread_create_wrapper, res,
- SIMIX_host_self_get_name(), 0, NULL,
- /*props */ NULL);
+ SIMIX_req_process_create(&res->s_process, name,
+ xbt_thread_create_wrapper, res,
+ SIMIX_host_self_get_name(), 0, NULL,
+ /*props */ NULL);
res->joinable = joinable;
res->done = 0;
res->cond = xbt_cond_init();