X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/aa0edd12af468a18224cc4dc2d129385e45ac294..dc061ae1d3507d0e3b7d3569553b31cb6709702e:/src/simix/smx_action.c diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index 90ed720921..ab885c7f47 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -31,13 +31,13 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender, smx_action_t act; /* check if the host is active */ - if (surf_workstation_model->extension. - workstation.get_state(sender->host) != SURF_RESOURCE_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->host) != SURF_RESOURCE_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); } @@ -45,6 +45,7 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender, /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); act->cond_list = xbt_fifo_new(); + act->sem_list = xbt_fifo_new(); /* initialize them */ act->name = xbt_strdup(name); @@ -52,8 +53,9 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender, act->surf_action = - surf_workstation_model->extension.workstation. - communicate(sender->host, receiver->host, size, rate); + 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); @@ -74,8 +76,8 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, smx_action_t act; /* check if the host is active */ - if (surf_workstation_model->extension. - workstation.get_state(host->host) != SURF_RESOURCE_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); } @@ -83,6 +85,7 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); act->cond_list = xbt_fifo_new(); + act->sem_list = xbt_fifo_new(); /* initialize them */ act->source = host; @@ -90,8 +93,7 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, /* set communication */ act->surf_action = - surf_workstation_model->extension.workstation.execute(host->host, - amount); + surf_workstation_model->extension.workstation.execute(host->host, amount); surf_workstation_model->action_data_set(act->surf_action, act); @@ -101,7 +103,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 @@ -112,8 +117,8 @@ smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) smx_action_t act; /* check if the host is active */ - if (surf_workstation_model->extension. - workstation.get_state(host->host) != SURF_RESOURCE_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); } @@ -121,14 +126,14 @@ smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); act->cond_list = xbt_fifo_new(); + act->sem_list = xbt_fifo_new(); /* initialize them */ act->source = host; act->name = xbt_strdup(name); act->surf_action = - surf_workstation_model->extension.workstation.sleep(host->host, - duration); + surf_workstation_model->extension.workstation.sleep(host->host, duration); surf_workstation_model->action_data_set(act->surf_action, act); @@ -142,7 +147,7 @@ smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) * This functions stops the execution of an action. It calls a surf functions. * \param action The SIMIX action */ -void SIMIX_action_cancel(smx_action_t action) +XBT_INLINE void SIMIX_action_cancel(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); @@ -160,12 +165,11 @@ void SIMIX_action_cancel(smx_action_t action) * \param action The SIMIX action * \param priority The new priority */ -void SIMIX_action_set_priority(smx_action_t action, double priority) +XBT_INLINE void SIMIX_action_set_priority(smx_action_t action, double priority) { xbt_assert0((action != NULL), "Invalid parameter"); - surf_workstation_model->set_priority(action->surf_action, - priority); + surf_workstation_model->set_priority(action->surf_action, priority); return; } @@ -188,11 +192,16 @@ int SIMIX_action_destroy(smx_action_t action) "Conditional list not empty %d. There is a problem. Cannot destroy it now!", xbt_fifo_size(action->cond_list)); + xbt_assert1((xbt_fifo_size(action->sem_list) == 0), + "Semaphore list not empty %d. There is a problem. Cannot destroy it now!", + xbt_fifo_size(action->sem_list)); + DEBUG1("Destroy action %p", action); if (action->name) xbt_free(action->name); xbt_fifo_free(action->cond_list); + xbt_fifo_free(action->sem_list); if (action->surf_action) action->surf_action->model_type->action_unref(action->surf_action); @@ -206,7 +215,7 @@ int SIMIX_action_destroy(smx_action_t action) * * \param action The SIMIX action */ -void SIMIX_action_use(smx_action_t action) +XBT_INLINE void SIMIX_action_use(smx_action_t action) { XBT_IN3("(%p:'%s',%d)", action, action->name, action->refcount); xbt_assert0((action != NULL), "Invalid parameter"); @@ -221,7 +230,7 @@ void SIMIX_action_use(smx_action_t action) * * \param action The SIMIX action */ -void SIMIX_action_release(smx_action_t action) +XBT_INLINE void SIMIX_action_release(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); @@ -231,43 +240,85 @@ void SIMIX_action_release(smx_action_t action) } /** - * \brief Set an action to a condition + * \brief Set an action to a condition * - * Creates the "link" between an action and a condition. You have to call this function when you create an action and want to wait its ending. - * \param action SIMIX action - * \param cond SIMIX cond + * Creates the "link" between an action and a condition. You have to call this function when you create an action and want to wait its ending. + * \param action SIMIX action + * \param cond SIMIX cond */ 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); } /** - * \brief Unset an action to a condition. + * \brief Unset an action to a condition. * - * Destroys the "links" from the condition to this action. - * \param action SIMIX action - * \param cond SIMIX cond + * Destroys the "links" from the condition to this action. + * \param action SIMIX action + * \param cond SIMIX cond */ -void SIMIX_unregister_action_to_condition(smx_action_t action, smx_cond_t cond) +void SIMIX_unregister_action_to_condition(smx_action_t action, + smx_cond_t cond) { 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); +} +/** + * \brief Link an action to a semaphore + * + * When the action terminates, the semaphore gets signaled automatically. + */ +XBT_INLINE void SIMIX_register_action_to_semaphore(smx_action_t action, smx_sem_t sem) { + + DEBUG2("Register action %p to semaphore %p (and otherwise)", action, sem); + xbt_fifo_push(sem->actions, action); + xbt_fifo_push(action->sem_list, sem); +} +/** + * \brief Unset an action to a semaphore. + * + * Destroys the "links" from the semaphore to this action. + */ +XBT_INLINE void SIMIX_unregister_action_to_semaphore(smx_action_t action, + smx_sem_t sem) +{ + xbt_fifo_remove_all(sem->actions, action); + xbt_fifo_remove_all(action->sem_list, sem); } /** @@ -276,10 +327,10 @@ void SIMIX_unregister_action_to_condition(smx_action_t action, smx_cond_t cond) * \param action The SIMIX action * \return Remains cost */ -double SIMIX_action_get_remains(smx_action_t action) +XBT_INLINE double SIMIX_action_get_remains(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - return action->surf_action->remains; + return surf_workstation_model->get_remains(action->surf_action); } smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, @@ -295,6 +346,7 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); act->cond_list = xbt_fifo_new(); + act->sem_list = xbt_fifo_new(); /* initialize them */ act->name = xbt_strdup(name); @@ -306,21 +358,19 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, workstation_list[i] = host_list[i]->host; act->surf_action = - surf_workstation_model->extension. - workstation.execute_parallel_task(host_nb, workstation_list, - computation_amount, - communication_amount, amount, rate); + surf_workstation_model->extension.workstation. + execute_parallel_task(host_nb, workstation_list, computation_amount, + communication_amount, amount, rate); surf_workstation_model->action_data_set(act->surf_action, act); return act; } -e_surf_action_state_t SIMIX_action_get_state(smx_action_t action) +XBT_INLINE 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-> - surf_action); + return surf_workstation_model->action_state_get(action->surf_action); } void __SIMIX_cond_display_actions(smx_cond_t cond) @@ -343,18 +393,26 @@ void __SIMIX_action_display_conditions(smx_action_t action) DEBUG1("\t %p", cond); } -char * SIMIX_action_get_name(smx_action_t action) +XBT_INLINE char *SIMIX_action_get_name(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); return action->name; } - -void SIMIX_action_signal_all(smx_action_t action) +/** @brief Change the name of the action. Warning, the string you provide is not strdup()ed */ +XBT_INLINE void SIMIX_action_set_name(smx_action_t action,char *name) { + xbt_free(action->name); + action->name = name; +} + +/** @brief broadcast any condition and release any semaphore including this action */ +void SIMIX_action_signal_all(smx_action_t action){ smx_cond_t cond; + smx_sem_t sem; - while((cond = xbt_fifo_pop(action->cond_list))) + while ((cond = xbt_fifo_pop(action->cond_list))) SIMIX_cond_broadcast(cond); - return; + while ((sem = xbt_fifo_pop(action->sem_list))) + SIMIX_sem_release(sem); }