From: velho Date: Thu, 18 Nov 2010 17:13:28 +0000 (+0000) Subject: Allow the get_route function to be used twice in a row. X-Git-Tag: v3_5~246 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/80fa0f3395b471f32dbdee9f320be5da1f4783b0?hp=31589d180181b5e0b8ab9e682a29500609bcf2ff Allow the get_route function to be used twice in a row. Before, the returned dynar was cleaned automatically by the second call to get_route. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8581 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/surf/network.c b/src/surf/network.c index 4a8e357c7e..73f0a60b05 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -539,7 +539,9 @@ static surf_action_t net_communicate(const char *src_name, xbt_dynar_t back_route = NULL; int constraints_per_variable = 0; - xbt_dynar_t route = global_routing->get_route(src_name, dst_name); + // I will need this route for some time so let's call get_route_no_cleanup + xbt_dynar_t route = global_routing->get_route_no_cleanup(src_name, dst_name); + if (sg_network_fullduplex == 1) { back_route = global_routing->get_route(dst_name, src_name); @@ -658,6 +660,7 @@ static surf_action_t net_communicate(const char *src_name, strncpy(action->dst_name, dst_name, strlen(dst_name) + 1); #endif + xbt_dynar_free(&route); XBT_OUT; return (surf_action_t) action; diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 966191009e..49c29de457 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -176,7 +176,8 @@ struct s_routing_global { xbt_dict_t where_network_elements; /* char* -> network_element_info_t */ void *loopback; size_t size_of_link; - xbt_dynar_t(*get_route) (const char *src, const char *dst); + const xbt_dynar_t(*get_route) (const char *src, const char *dst); + xbt_dynar_t(*get_route_no_cleanup) (const char *src, const char *dst); xbt_dynar_t(*get_onelink_routes) (void); e_surf_network_element_type_t(*get_network_element_type) (const char *name); diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 2b04d72fb4..7e86bbcb16 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -728,9 +728,10 @@ static route_extended_t _get_route(const char *src, const char *dst) * \param dst the destination host name * * walk through the routing components tree and find a route between hosts - * by calling the differents "get_route" functions in each routing component + * by calling the differents "get_route" functions in each routing component. + * No need to free the returned dynar. It will be freed at the next call. */ -static xbt_dynar_t get_route(const char *src, const char *dst) +static const xbt_dynar_t get_route(const char *src, const char *dst) { route_extended_t e_route; @@ -763,6 +764,23 @@ static xbt_dynar_t get_route(const char *src, const char *dst) return global_routing->last_route; } +/** + * \brief Generic method: find a route between hosts + * + * \param src the source host name + * \param dst the destination host name + * + * walk through the routing components tree and find a route between hosts + * by calling the differents "get_route" functions in each routing component. + * Leaves the caller the responsability to clean the returned dynar. + */ +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; +} + /** * \brief Recursive function for finalize * @@ -862,6 +880,7 @@ void routing_model_create(size_t size_of_links, void *loopback) global_routing->where_network_elements = xbt_dict_new(); global_routing->root = NULL; global_routing->get_route = get_route; + global_routing->get_route_no_cleanup = get_route_no_cleanup; global_routing->get_onelink_routes = get_onelink_routes; global_routing->get_network_element_type = get_network_element_type; global_routing->finalize = finalize;