X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9189fe94c14ef9e31142d1603a1979ea7e731a0a..7d0c4c0adbba2982f29444f00d1e70ad6b6aacdf:/src/gras/Msg/timer.c diff --git a/src/gras/Msg/timer.c b/src/gras/Msg/timer.c index 3c2d398aaa..124984053e 100644 --- a/src/gras/Msg/timer.c +++ b/src/gras/Msg/timer.c @@ -18,7 +18,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_timer,gras, /** @brief Request \a action to be called once in \a delay seconds */ void gras_timer_delay(double delay, void_f_void_t action) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); gras_timer_t timer = xbt_dynar_push_ptr(pd->timers); @@ -31,7 +31,7 @@ void gras_timer_delay(double delay, void_f_void_t action) { /** @brief Request \a action to be called every \a interval seconds */ void gras_timer_repeat(double interval, void_f_void_t action) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); gras_timer_t timer = xbt_dynar_push_ptr(pd->timers); @@ -44,7 +44,7 @@ void gras_timer_repeat(double interval, void_f_void_t action) { /** @brief Cancel a delayed task */ void gras_timer_cancel_delay(double interval, void_f_void_t action) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); int cursor,found; s_gras_timer_t timer; @@ -67,7 +67,7 @@ void gras_timer_cancel_delay(double interval, void_f_void_t action) { /** @brief Cancel a repetitive task */ void gras_timer_cancel_repeat(double interval, void_f_void_t action) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); int cursor,found; s_gras_timer_t timer; @@ -89,7 +89,7 @@ void gras_timer_cancel_repeat(double interval, void_f_void_t action) { /** @brief Cancel all delayed tasks */ void gras_timer_cancel_delay_all(void) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); int cursor, found; s_gras_timer_t timer; @@ -109,7 +109,7 @@ void gras_timer_cancel_delay_all(void) { /** @brief Cancel all repetitive tasks */ void gras_timer_cancel_repeat_all(void){ - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); int cursor, found; s_gras_timer_t timer; @@ -128,20 +128,20 @@ void gras_timer_cancel_repeat_all(void){ /** @brief Cancel all delayed and repetitive tasks */ void gras_timer_cancel_all(void) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); xbt_dynar_reset( pd->timers ); } /* returns 0 if it handled a timer, or the delay until next timer, or -1 if no armed timer */ double gras_msg_timer_handle(void) { - gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg"); + gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id); int cursor; gras_timer_t timer; double now=gras_os_time(); double untilnext = -1.0; - for (cursor=0; cursor < xbt_dynar_length(pd->timers); cursor++) { + for (cursor=0; cursor < (int)xbt_dynar_length(pd->timers); cursor++) { double untilthis; timer = xbt_dynar_get_ptr (pd->timers, cursor); @@ -150,22 +150,23 @@ double gras_msg_timer_handle(void) { DEBUG2("Action %p expires in %f", timer->action, untilthis); if (untilthis <= 0.0) { + void_f_void_t action = timer->action; - DEBUG5("[%.0f] Serve %s action %p (%f<%f)",gras_os_time(), + DEBUG5("[%.0f] Serve %s action %p (%f<%f)",gras_os_time(), timer->repeat ? "repetitive" : "delayed", timer->action, timer->expiry, now); - timer->action(); - if (timer->repeat) { - timer->expiry = now + timer->period; - DEBUG4("[%.0f] Re-arm repetitive action %p for %f (period=%f)", - gras_os_time(), - timer->action, timer->expiry, timer->period); - } else { - DEBUG2("[%.0f] Remove %p now that it's done", gras_os_time(), timer->action); - xbt_dynar_cursor_rm(pd->timers, &cursor); - } - return 0.0; + if (timer->repeat) { + timer->expiry = now + timer->period; + DEBUG4("[%.0f] Re-arm repetitive action %p for %f (period=%f)", + gras_os_time(), + timer->action, timer->expiry, timer->period); + } else { + DEBUG2("[%.0f] Remove %p now that it's done", gras_os_time(), timer->action); + xbt_dynar_cursor_rm(pd->timers, &cursor); + } + (*action)(); + return 0.0; } else if (untilthis < untilnext || untilnext == -1) { untilnext = untilthis; }