Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allow the get_route function to be used twice in a row.
authorvelho <velho@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 18 Nov 2010 17:13:28 +0000 (17:13 +0000)
committervelho <velho@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 18 Nov 2010 17:13:28 +0000 (17:13 +0000)
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

src/surf/network.c
src/surf/surf_private.h
src/surf/surf_routing.c

index 4a8e357..73f0a60 100644 (file)
@@ -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;
index 9661910..49c29de 100644 (file)
@@ -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);
index 2b04d72..7e86bbc 100644 (file)
@@ -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;