From: alegrand Date: Mon, 8 Jun 2009 14:16:33 +0000 (+0000) Subject: Cleaner use of the refcount introduced by Henri. X-Git-Tag: SVN~1321 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2643bb7bdcf3eb79c4a0ba6c38435096411e85ff?ds=sidebyside Cleaner use of the refcount introduced by Henri. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6319 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/include/simix/simix.h b/src/include/simix/simix.h index ae70ee33e8..e0bff3ad5b 100644 --- a/src/include/simix/simix.h +++ b/src/include/simix/simix.h @@ -154,7 +154,9 @@ XBT_PUBLIC(smx_action_t) SIMIX_action_sleep(smx_host_t host, double amount); XBT_PUBLIC(void) SIMIX_action_cancel(smx_action_t action); XBT_PUBLIC(void) SIMIX_action_set_priority(smx_action_t action, double priority); -XBT_PUBLIC(void) SIMIX_action_destroy(smx_action_t action); +XBT_PUBLIC(int) SIMIX_action_destroy(smx_action_t action); +XBT_PUBLIC(void) SIMIX_action_use(smx_action_t action); +XBT_PUBLIC(void) SIMIX_action_release(smx_action_t action); XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond); XBT_PUBLIC(void) SIMIX_unregister_action_to_condition(smx_action_t action, diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index 8be0ef261b..ec9ae9c495 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -163,7 +163,8 @@ void SIMIX_action_cancel(smx_action_t action) DEBUG1("Cancel action %p", action); if (action->simdata->surf_action) { surf_workstation_model->common_public->action_cancel(action-> - simdata->surf_action); + simdata-> + surf_action); } return; } @@ -191,10 +192,15 @@ void SIMIX_action_set_priority(smx_action_t action, double priority) * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it. * \param action The SIMIX action */ -void SIMIX_action_destroy(smx_action_t action) +int SIMIX_action_destroy(smx_action_t action) { + XBT_IN3("(%p:'%s',%d)", action, action->name, action->refcount); xbt_assert0((action != NULL), "Invalid parameter"); + action->refcount--; + if (action->refcount > 0) + return 0; + xbt_assert1((xbt_fifo_size(action->cond_list) == 0), "Conditional list not empty %d. There is a problem. Cannot destroy it now!", xbt_fifo_size(action->cond_list)); @@ -211,6 +217,35 @@ void SIMIX_action_destroy(smx_action_t action) xbt_free(action->simdata); xbt_free(action); + return 1; +} + +/** + * \brief Increase refcount of anan action + * + * \param action The SIMIX action + */ +void SIMIX_action_use(smx_action_t action) +{ + XBT_IN3("(%p:'%s',%d)", action, action->name, action->refcount); + xbt_assert0((action != NULL), "Invalid parameter"); + + action->refcount++; + + return; +} + +/** + * \brief Decrease refcount of anan action + * + * \param action The SIMIX action + */ +void SIMIX_action_release(smx_action_t action) +{ + xbt_assert0((action != NULL), "Invalid parameter"); + + action->refcount--; + return; } @@ -323,7 +358,7 @@ void __SIMIX_cond_display_actions(smx_cond_t cond) DEBUG1("Actions for condition %p", cond); xbt_fifo_foreach(cond->actions, item, action, smx_action_t) - DEBUG2("\t %p [%s]", action,action->name); + DEBUG2("\t %p [%s]", action, action->name); } void __SIMIX_action_display_conditions(smx_action_t action)