X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/824b99a5272ff8ce814336ab8bc9817eecd6de60..2da40b8c48f7615cb7fb4bdab32f4d96e4541d91:/src/simix/smx_action.c diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index d588ae9d9a..a61c9230eb 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -29,35 +29,33 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender, double size, double rate) { smx_action_t act; - smx_simdata_action_t simdata; /* check if the host is active */ - if (surf_workstation_model->extension. - workstation.get_state(sender->simdata->host) != SURF_CPU_ON) { + if (surf_workstation_model->extension.workstation.get_state(sender->host) != + SURF_RESOURCE_ON) { THROW1(network_error, 0, "Host %s failed, you cannot call this function", sender->name); } - if (surf_workstation_model->extension. - workstation.get_state(receiver->simdata->host) != SURF_CPU_ON) { + if (surf_workstation_model->extension.workstation. + get_state(receiver->host) != SURF_RESOURCE_ON) { THROW1(network_error, 0, "Host %s failed, you cannot call this function", receiver->name); } /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); - act->simdata = xbt_new0(s_smx_simdata_action_t, 1); - simdata = act->simdata; act->cond_list = xbt_fifo_new(); /* initialize them */ act->name = xbt_strdup(name); - simdata->source = sender; + act->source = sender; - simdata->surf_action = - surf_workstation_model->extension.workstation. - communicate(sender->simdata->host, receiver->simdata->host, size, rate); - surf_workstation_model->action_data_set(simdata->surf_action, act); + act->surf_action = + surf_workstation_model->extension.workstation.communicate(sender->host, + receiver->host, + size, rate); + surf_workstation_model->action_data_set(act->surf_action, act); DEBUG1("Create communicate action %p", act); return act; @@ -75,31 +73,27 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, double amount) { smx_action_t act; - smx_simdata_action_t simdata; /* check if the host is active */ - if (surf_workstation_model->extension. - workstation.get_state(host->simdata->host) != SURF_CPU_ON) { + if (surf_workstation_model->extension.workstation.get_state(host->host) != + SURF_RESOURCE_ON) { THROW1(host_error, 0, "Host %s failed, you cannot call this function", host->name); } /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); - act->simdata = xbt_new0(s_smx_simdata_action_t, 1); - simdata = act->simdata; act->cond_list = xbt_fifo_new(); /* initialize them */ - simdata->source = host; + act->source = host; act->name = xbt_strdup(name); /* set communication */ - simdata->surf_action = - surf_workstation_model->extension.workstation.execute(host->simdata->host, - amount); + act->surf_action = + surf_workstation_model->extension.workstation.execute(host->host, amount); - surf_workstation_model->action_data_set(simdata->surf_action, act); + surf_workstation_model->action_data_set(act->surf_action, act); DEBUG1("Create execute action %p", act); return act; @@ -107,7 +101,10 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, /** \brief Creates a new sleep SIMIX action. * - * This function creates a SURF action and allocates the data necessary to create the SIMIX action. It can raise a host_error exception if the host crashed. The default SIMIX name of the action is "sleep". + * This function creates a SURF action and allocates the data necessary + * to create the SIMIX action. It can raise a host_error exception if the + * host crashed. The default SIMIX name of the action is "sleep". + * * \param host SIMIX host where the sleep will run. * \param duration Time duration of the sleep. * \return A new SIMIX action @@ -115,31 +112,27 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) { char name[] = "sleep"; - smx_simdata_action_t simdata; smx_action_t act; /* check if the host is active */ - if (surf_workstation_model->extension. - workstation.get_state(host->simdata->host) != SURF_CPU_ON) { + if (surf_workstation_model->extension.workstation.get_state(host->host) != + SURF_RESOURCE_ON) { THROW1(host_error, 0, "Host %s failed, you cannot call this function", host->name); } /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); - act->simdata = xbt_new0(s_smx_simdata_action_t, 1); - simdata = act->simdata; act->cond_list = xbt_fifo_new(); /* initialize them */ - simdata->source = host; + act->source = host; act->name = xbt_strdup(name); - simdata->surf_action = - surf_workstation_model->extension.workstation.sleep(host->simdata->host, - duration); + act->surf_action = + surf_workstation_model->extension.workstation.sleep(host->host, duration); - surf_workstation_model->action_data_set(simdata->surf_action, act); + surf_workstation_model->action_data_set(act->surf_action, act); DEBUG1("Create sleep action %p", act); return act; @@ -156,8 +149,8 @@ void SIMIX_action_cancel(smx_action_t action) xbt_assert0((action != NULL), "Invalid parameter"); DEBUG1("Cancel action %p", action); - if (action->simdata->surf_action) { - surf_workstation_model->action_cancel(action->simdata->surf_action); + if (action->surf_action) { + surf_workstation_model->action_cancel(action->surf_action); } return; } @@ -171,11 +164,9 @@ void SIMIX_action_cancel(smx_action_t action) */ void SIMIX_action_set_priority(smx_action_t action, double priority) { - xbt_assert0((action != NULL) - && (action->simdata != NULL), "Invalid parameter"); + xbt_assert0((action != NULL), "Invalid parameter"); - surf_workstation_model->set_priority(action->simdata->surf_action, - priority); + surf_workstation_model->set_priority(action->surf_action, priority); return; } @@ -204,11 +195,9 @@ int SIMIX_action_destroy(smx_action_t action) xbt_fifo_free(action->cond_list); - if (action->simdata->surf_action) - action->simdata->surf_action->model_type->action_free(action-> - simdata->surf_action); + if (action->surf_action) + action->surf_action->model_type->action_unref(action->surf_action); - xbt_free(action->simdata); xbt_free(action); return 1; } @@ -254,13 +243,23 @@ void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); DEBUG2("Register action %p to cond %p", action, cond); - __SIMIX_cond_display_actions(cond); + if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + __SIMIX_cond_display_actions(cond); + xbt_fifo_push(cond->actions, action); - __SIMIX_cond_display_actions(cond); + + if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + __SIMIX_cond_display_actions(cond); + DEBUG2("Register condition %p to action %p", cond, action); - __SIMIX_action_display_conditions(action); + + if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + __SIMIX_action_display_conditions(action); + xbt_fifo_push(action->cond_list, cond); - __SIMIX_action_display_conditions(action); + + if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + __SIMIX_action_display_conditions(action); } /** @@ -275,12 +274,21 @@ void SIMIX_unregister_action_to_condition(smx_action_t action, { xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); - __SIMIX_cond_display_actions(cond); + if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + __SIMIX_cond_display_actions(cond); + xbt_fifo_remove_all(cond->actions, action); - __SIMIX_cond_display_actions(cond); - __SIMIX_action_display_conditions(action); + + if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + __SIMIX_cond_display_actions(cond); + + if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + __SIMIX_action_display_conditions(action); + xbt_fifo_remove_all(action->cond_list, cond); - __SIMIX_action_display_conditions(action); + + if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + __SIMIX_action_display_conditions(action); } /** @@ -292,7 +300,7 @@ void SIMIX_unregister_action_to_condition(smx_action_t action, double SIMIX_action_get_remains(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - return action->simdata->surf_action->remains; + return surf_workstation_model->get_remains(action->surf_action); } smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, @@ -302,14 +310,11 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, double amount, double rate) { void **workstation_list = NULL; - smx_simdata_action_t simdata; smx_action_t act; int i; /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); - act->simdata = xbt_new0(s_smx_simdata_action_t, 1); - simdata = act->simdata; act->cond_list = xbt_fifo_new(); /* initialize them */ @@ -319,15 +324,14 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, workstation_list = xbt_new0(void *, host_nb); for (i = 0; i < host_nb; i++) - workstation_list[i] = host_list[i]->simdata->host; + workstation_list[i] = host_list[i]->host; - simdata->surf_action = - surf_workstation_model->extension. - workstation.execute_parallel_task(host_nb, workstation_list, - computation_amount, - communication_amount, amount, rate); + act->surf_action = + surf_workstation_model->extension.workstation. + execute_parallel_task(host_nb, workstation_list, computation_amount, + communication_amount, amount, rate); - surf_workstation_model->action_data_set(simdata->surf_action, act); + surf_workstation_model->action_data_set(act->surf_action, act); return act; } @@ -335,9 +339,7 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, e_surf_action_state_t SIMIX_action_get_state(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - return surf_workstation_model->action_state_get(action->simdata-> - surf_action); - + return surf_workstation_model->action_state_get(action->surf_action); } void __SIMIX_cond_display_actions(smx_cond_t cond) @@ -359,3 +361,24 @@ void __SIMIX_action_display_conditions(smx_action_t action) xbt_fifo_foreach(action->cond_list, item, cond, smx_cond_t) DEBUG1("\t %p", cond); } + +char *SIMIX_action_get_name(smx_action_t action) +{ + xbt_assert0((action != NULL), "Invalid parameter"); + return action->name; +} +/** @brief Change the name of the action. Warning, the string you provide is not strdup()ed */ +void SIMIX_action_set_name(smx_action_t action,char *name) +{ + action->name = name; +} + +void SIMIX_action_signal_all(smx_action_t action) +{ + smx_cond_t cond; + + while ((cond = xbt_fifo_pop(action->cond_list))) + SIMIX_cond_broadcast(cond); + + return; +}