From: thiery Date: Thu, 27 Jan 2011 16:42:16 +0000 (+0000) Subject: Replace the return value of SIMIX_req_process_create() by a parameter. X-Git-Tag: v3.6_beta2~408 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9a7c6c8f75db930814b5ca356795f8ff2347c5d7 Replace the return value of SIMIX_req_process_create() by a parameter. This is because the new process created may start its execution before this function returns, making the assignment of the return value occur too late. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9521 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/simix/datatypes.h b/include/simix/datatypes.h index f905acf2e5..e69c1dfe3e 100644 --- a/include/simix/datatypes.h +++ b/include/simix/datatypes.h @@ -70,6 +70,7 @@ typedef struct s_smx_process *smx_process_t; /* 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. @@ -77,7 +78,8 @@ typedef struct s_smx_process *smx_process_t; * 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 *, diff --git a/include/simix/simix.h b/include/simix/simix.h index 4d95ee6b07..956902ec31 100644 --- a/include/simix/simix.h +++ b/include/simix/simix.h @@ -117,12 +117,13 @@ XBT_PUBLIC(e_smx_state_t) SIMIX_req_host_execution_wait(smx_action_t execution); /**************************** 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); diff --git a/src/gras/Virtu/sg_process.c b/src/gras/Virtu/sg_process.c index d16c067b43..766daa20cc 100644 --- a/src/gras/Virtu/sg_process.c +++ b/src/gras/Virtu/sg_process.c @@ -27,7 +27,8 @@ void gras_agent_spawn(const char *name, 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); } diff --git a/src/msg/m_process.c b/src/msg/m_process.c index ea8faa63f6..d6598a9c3a 100644 --- a/src/msg/m_process.c +++ b/src/msg/m_process.c @@ -58,15 +58,16 @@ void __MSG_process_cleanup(smx_process_t smx_proc) } /* 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 @@ -176,9 +177,10 @@ m_process_t MSG_process_create_with_environment(const char *name, 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 */ diff --git a/src/msg/private.h b/src/msg/private.h index 8eddd6b917..a6e91942f4 100644 --- a/src/msg/private.h +++ b/src/msg/private.h @@ -104,10 +104,10 @@ void __MSG_host_destroy(m_host_t host); 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); diff --git a/src/simix/process_private.h b/src/simix/process_private.h index e1c44b0a99..e6f89a91a1 100644 --- a/src/simix/process_private.h +++ b/src/simix/process_private.h @@ -45,12 +45,13 @@ typedef struct s_smx_process_arg { 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); diff --git a/src/simix/smurf_private.h b/src/simix/smurf_private.h index 5f7dcb407e..972c6bc392 100644 --- a/src/simix/smurf_private.h +++ b/src/simix/smurf_private.h @@ -213,6 +213,7 @@ typedef struct s_smx_req { } host_execution_wait; struct { + smx_process_t *process; const char *name; xbt_main_func_t code; void *data; @@ -220,7 +221,6 @@ typedef struct s_smx_req { int argc; char **argv; xbt_dict_t properties; - smx_process_t result; } process_create; struct { diff --git a/src/simix/smx_deployment.c b/src/simix/smx_deployment.c index c3b977d0a0..06b3aa42c5 100644 --- a/src/simix/smx_deployment.c +++ b/src/simix/smx_deployment.c @@ -48,7 +48,7 @@ static void parse_argument(void) 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]; @@ -67,16 +67,15 @@ static void parse_process_finalize(void) 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); diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index eff7ab721b..d267eb9e47 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -96,7 +96,9 @@ smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) { 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, @@ -105,7 +107,9 @@ smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) { args->properties); } else { - process = SIMIX_process_create(args->name, + SIMIX_process_create( + &process, + args->name, args->code, args->data, args->hostname, @@ -128,14 +132,15 @@ smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) { * * \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); @@ -145,38 +150,36 @@ smx_process_t SIMIX_process_create(const char *name, 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; } /** @@ -276,8 +279,6 @@ void SIMIX_pre_process_suspend(smx_req_t req) 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, diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index da3f652556..bfc0443fb0 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -319,7 +319,8 @@ void SIMIX_request_pre(smx_req_t req, int value) 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, diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 033d4cabdf..2bde738972 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -296,8 +296,9 @@ e_smx_state_t SIMIX_req_host_execution_wait(smx_action_t execution) /** * \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. @@ -306,18 +307,18 @@ e_smx_state_t SIMIX_req_host_execution_wait(smx_action_t execution) * \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; @@ -326,7 +327,6 @@ smx_process_t SIMIX_req_process_create(const char *name, req->process_create.argv = argv; req->process_create.properties = properties; SIMIX_request_push(); - return req->process_create.result; } /** \brief Kills a SIMIX process. @@ -374,6 +374,8 @@ void SIMIX_req_process_change_host(smx_process_t process, const char *source, co */ 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; diff --git a/src/xbt/xbt_sg_synchro.c b/src/xbt/xbt_sg_synchro.c index 6e9b0aea54..ec377f65f8 100644 --- a/src/xbt/xbt_sg_synchro.c +++ b/src/xbt/xbt_sg_synchro.c @@ -63,10 +63,10 @@ xbt_thread_t xbt_thread_create(const char *name, void_f_pvoid_t code, 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();