From e093b81565d3778fa1e829438f4ef70758a1e886 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 16 May 2011 17:02:46 +0200 Subject: [PATCH] Define get_route_latency. --- src/surf/surf_routing.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 50504869e5..0bd75d6794 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -643,7 +643,7 @@ static void elements_father(const char *src, const char *dst, /* Global Business methods */ /** - * \brief Recursive function for get_route and get_latency + * \brief Recursive function for get_route_latency * * \param src the source host name * \param dst the destination host name @@ -775,6 +775,22 @@ static void _get_route_latency(const char *src, const char *dst, } } +/** + * \brief Generic function for get_route, get_route_no_cleanup, and get_latency + */ +static void get_route_latency(const char *src, const char *dst, + xbt_dynar_t *route, double *latency, int cleanup) +{ + _get_route_latency(src, dst, route, latency); + xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst); + xbt_assert(!latency || *latency >= 0.0, + "latency error on route between \"%s\" and \"%s\"", src, dst); + if (route) { + xbt_dynar_free(&global_routing->last_route); + global_routing->last_route = cleanup ? *route : NULL; + } +} + /** * \brief Generic method: find a route between hosts * @@ -787,15 +803,8 @@ static void _get_route_latency(const char *src, const char *dst, */ static xbt_dynar_t get_route(const char *src, const char *dst) { - xbt_dynar_t route = NULL; - - _get_route_latency(src, dst, &route, NULL); - xbt_assert(route, "no route between \"%s\" and \"%s\"", src, dst); - - xbt_dynar_free(&global_routing->last_route); - global_routing->last_route = route; - + get_route_latency(src, dst, &route, NULL, 1); return route; } @@ -811,18 +820,16 @@ static xbt_dynar_t get_route(const char *src, const char *dst) */ static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst) { - xbt_dynar_t d = get_route(src,dst); - global_routing->last_route = NULL; - return d; + xbt_dynar_t route = NULL; + get_route_latency(src, dst, &route, NULL, 0); + return route; } /*Get Latency*/ static double get_latency(const char *src, const char *dst) { - double latency = -1.0; - _get_route_latency(src, dst, NULL, &latency); - xbt_assert(latency>=0.0, "no route between \"%s\" and \"%s\"", src, dst); + get_route_latency(src, dst, NULL, &latency, 0); return latency; } -- 2.20.1