Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill small crufts here and there
[simgrid.git] / src / surf / surf_routing.c
index f7bd97d..07162fa 100644 (file)
@@ -32,13 +32,11 @@ int ROUTING_ASR_LEVEL;          //Routing level
 int COORD_ASR_LEVEL;            //Coordinates level
 int NS3_ASR_LEVEL;              //host node for ns3
 
-static xbt_dict_t patterns = NULL;
 static xbt_dict_t random_value = NULL;
 
 /* Global vars */
 routing_global_t global_routing = NULL;
 AS_t current_routing = NULL;
-routing_model_description_t current_routing_model = NULL;
 
 /* global parse functions */
 xbt_dynar_t link_list = NULL;   /* temporary store of current list link of a route */
@@ -375,7 +373,7 @@ void routing_AS_end()
                 (void *) info);
 
     if (current_routing->routing->end)
-      (*(current_routing->routing->end)) ();
+      (*(current_routing->routing->end)) (current_routing);
     current_routing = current_routing->routing_father;
   }
 }
@@ -661,9 +659,7 @@ static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
   return route;
 }
 
-/*Get Latency*/
-static double get_latency(const char *src, const char *dst)
-{
+static double get_latency(const char *src, const char *dst) {
   double latency = -1.0;
   get_route_latency(src, dst, NULL, &latency, 0);
   return latency;
@@ -677,23 +673,17 @@ static double get_latency(const char *src, const char *dst)
  * This fuction is call by "finalize". It allow to finalize the 
  * AS or routing components. It delete all the structures.
  */
-static void _finalize(AS_t rc)
-{
-  if (rc) {
-    xbt_dict_cursor_t cursor = NULL;
-    char *key;
-    AS_t elem;
-    xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
-      _finalize(elem);
-    }
-    xbt_dict_t tmp_sons = rc->routing_sons;
-    char *tmp_name = rc->name;
-    xbt_dict_free(&tmp_sons);
-    xbt_free(tmp_name);
-    xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
-               current_routing->name);
-    (*(rc->finalize)) (rc);
-  }
+static void finalize_rec(AS_t as) {
+  xbt_dict_cursor_t cursor = NULL;
+  char *key;
+  AS_t elem;
+
+  xbt_dict_foreach(as->routing_sons, cursor, key, elem)
+  finalize_rec(elem);
+
+  xbt_dict_free(&as->routing_sons);
+  xbt_free(as->name);
+  as->finalize(as);
 }
 
 /**
@@ -702,13 +692,9 @@ static void _finalize(AS_t rc)
  * walk through the routing components tree and delete the structures
  * by calling the different "finalize" functions in each routing component
  */
-static void finalize(void)
-{
-  /* delete recursively all the tree */
-  _finalize(global_routing->root);
-  /* delete last_route */
-  xbt_dynar_free(&(global_routing->last_route));
-  /* delete global routing structure */
+static void finalize(void) {
+  finalize_rec(global_routing->root);
+  xbt_dynar_free(&global_routing->last_route);
   xbt_free(global_routing);
 }
 
@@ -836,14 +822,14 @@ void routing_model_create(size_t size_of_links, void *loopback)
 static void routing_parse_cluster(void)
 {
   char *host_id, *groups, *link_id = NULL;
+  xbt_dict_t patterns = NULL;
 
   s_sg_platf_host_cbarg_t host;
   s_sg_platf_link_cbarg_t link;
 
   if (strcmp(struct_cluster->availability_trace, "")
       || strcmp(struct_cluster->state_trace, "")) {
-    if (xbt_dict_size(patterns) == 0)
-      patterns = xbt_dict_new();
+    patterns = xbt_dict_new();
     xbt_dict_set(patterns, "id", xbt_strdup(struct_cluster->id), free);
     xbt_dict_set(patterns, "prefix", xbt_strdup(struct_cluster->prefix), free);
     xbt_dict_set(patterns, "suffix", xbt_strdup(struct_cluster->suffix), free);
@@ -887,8 +873,7 @@ static void routing_parse_cluster(void)
       if (strcmp(struct_cluster->availability_trace, "")) {
         xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
         char *tmp_availability_file =
-            xbt_strdup(struct_cluster->availability_trace);
-        xbt_str_varsubst(tmp_availability_file, patterns);
+            xbt_str_varsubst(struct_cluster->availability_trace, patterns);
         XBT_DEBUG("\tavailability_file=\"%s\"", tmp_availability_file);
         host.power_trace = tmgr_trace_new(tmp_availability_file);
         xbt_free(tmp_availability_file);
@@ -896,8 +881,8 @@ static void routing_parse_cluster(void)
         XBT_DEBUG("\tavailability_file=\"\"");
       }
       if (strcmp(struct_cluster->state_trace, "")) {
-        char *tmp_state_file = xbt_strdup(struct_cluster->state_trace);
-        xbt_str_varsubst(tmp_state_file, patterns);
+        char *tmp_state_file =
+            xbt_str_varsubst(struct_cluster->state_trace, patterns);
         XBT_DEBUG("\tstate_file=\"%s\"", tmp_state_file);
         host.state_trace = tmgr_trace_new(tmp_state_file);
         xbt_free(tmp_state_file);
@@ -1034,19 +1019,14 @@ static void routing_parse_cluster(void)
   xbt_dynar_free(&radical_elements);
   xbt_free(new_suffix);
 
-  if (strcmp(struct_cluster->availability_trace, "")
-      || strcmp(struct_cluster->state_trace, ""))
-    xbt_dict_free(&patterns);
-
   XBT_DEBUG("</AS>");
   sg_platf_new_AS_end();
   XBT_DEBUG(" ");
+  xbt_dict_free(&patterns); // no op if it were never set
 }
 
-static void routing_parse_postparse(void)
-{
+static void routing_parse_postparse(void) {
   xbt_dict_free(&random_value);
-  xbt_dict_free(&patterns);
 }
 
 static void routing_parse_peer(sg_platf_peer_cbarg_t peer)