X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8275b53588fb2f78bca67abb7ef3e2944f7f6e9f..5f2cfc086eff62c591fab6837547190ad9582671:/src/simix/smx_process.c diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 31843beba0..8a90a1ee98 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, @@ -403,14 +404,6 @@ int SIMIX_process_is_suspended(smx_process_t process) return process->suspended; } -int SIMIX_process_is_enabled(smx_process_t process) -{ - if (process->request.call != REQ_NO_REQ && SIMIX_request_is_enabled(&process->request)) - return TRUE; - - return FALSE; -} - xbt_dict_t SIMIX_process_get_properties(smx_process_t process) { return process->properties; @@ -419,8 +412,10 @@ xbt_dict_t SIMIX_process_get_properties(smx_process_t process) void SIMIX_pre_process_sleep(smx_req_t req) { if (MC_IS_ENABLED) { + MC_process_clock_add(req->issuer, req->process_sleep.duration); req->process_sleep.result = SIMIX_DONE; SIMIX_request_answer(req); + return; } smx_action_t action = SIMIX_process_sleep(req->issuer, req->process_sleep.duration); xbt_fifo_push(action->request_list, req); @@ -439,10 +434,9 @@ smx_action_t SIMIX_process_sleep(smx_process_t process, double duration) host->name); } - action = xbt_new0(s_smx_action_t, 1); + action = xbt_mallocator_get(simix_global->action_mallocator); action->type = SIMIX_ACTION_SLEEP; - action->request_list = xbt_fifo_new(); - action->name = xbt_strdup("sleep"); + action->name = NULL; #ifdef HAVE_TRACING action->category = NULL; #endif @@ -459,30 +453,41 @@ smx_action_t SIMIX_process_sleep(smx_process_t process, double duration) void SIMIX_post_process_sleep(smx_action_t action) { - e_smx_state_t state = SIMIX_action_map_state(surf_workstation_model->action_state_get(action->sleep.surf_sleep)); smx_req_t req; + e_smx_state_t state; while ((req = xbt_fifo_shift(action->request_list))) { + + switch(surf_workstation_model->action_state_get(action->sleep.surf_sleep)){ + case SURF_ACTION_FAILED: + state = SIMIX_SRC_HOST_FAILURE; + break; + + case SURF_ACTION_DONE: + state = SIMIX_DONE; + break; + + default: + THROW_IMPOSSIBLE; + break; + } req->process_sleep.result = state; req->issuer->waiting_action = NULL; SIMIX_request_answer(req); } - SIMIX_process_sleep_destroy(action); } void SIMIX_process_sleep_destroy(smx_action_t action) { DEBUG1("Destroy action %p", action); - if (action->name) - xbt_free(action->name); + xbt_free(action->name); if (action->sleep.surf_sleep) action->sleep.surf_sleep->model_type->action_unref(action->sleep.surf_sleep); #ifdef HAVE_TRACING TRACE_smx_action_destroy(action); #endif - xbt_fifo_free(action->request_list); - xbt_free(action); + xbt_mallocator_release(simix_global->action_mallocator, action); } void SIMIX_process_sleep_suspend(smx_action_t action)