Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
factorize the routing_exit functionality, and ensure that no model can forget to...
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 10 Nov 2011 16:47:24 +0000 (17:47 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 10 Nov 2011 17:44:53 +0000 (18:44 +0100)
src/surf/network.c
src/surf/network_im.c
src/surf/surf.c
src/surf/surf_private.h
src/surf/surf_routing.c
src/surf/workstation_ptask_L07.c

index e3bd03a..67213b5 100644 (file)
@@ -785,8 +785,6 @@ static void net_finalize(void)
   surf_model_exit(surf_network_model);
   surf_network_model = NULL;
 
-  global_routing->finalize();
-
   lmm_system_free(network_maxmin_system);
   network_maxmin_system = NULL;
 }
index d381637..b15b936 100644 (file)
@@ -810,8 +810,6 @@ static void im_net_finalize(void)
   surf_model_exit(surf_network_model);
   surf_network_model = NULL;
 
-  global_routing->finalize();
-
   lmm_system_free(network_im_maxmin_system);
   network_im_maxmin_system = NULL;
 
index f6d9f20..2f90fa9 100644 (file)
@@ -366,6 +366,7 @@ void surf_exit(void)
   xbt_dynar_foreach(model_list, iter, model)
       model->model_private->finalize();
   xbt_dynar_free(&model_list);
+  routing_exit();
 
   if (maxmin_system) {
     lmm_system_free(maxmin_system);
index 8739042..7c2e4ca 100644 (file)
@@ -177,11 +177,11 @@ struct s_routing_global {
   void (*get_route_latency)(const char *src, const char *dst,
                             xbt_dynar_t *route, double *latency, int cleanup);
   e_surf_network_element_type_t(*get_network_element_type) (const char *name);
-  void (*finalize) (void);
   xbt_dynar_t last_route;
 };
 
 XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback);
+XBT_PUBLIC(void) routing_exit(void);
 XBT_PUBLIC(void) routing_register_callbacks(void);
 
 /**
index 07162fa..0f469d5 100644 (file)
@@ -665,38 +665,6 @@ static double get_latency(const char *src, const char *dst) {
   return latency;
 }
 
-/**
- * \brief Recursive function for finalize
- *
- * \param rc the source host name 
- * 
- * This fuction is call by "finalize". It allow to finalize the 
- * AS or routing components. It delete all the structures.
- */
-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);
-}
-
-/**
- * \brief Generic method: delete all the routing structures
- * 
- * walk through the routing components tree and delete the structures
- * by calling the different "finalize" functions in each routing component
- */
-static void finalize(void) {
-  finalize_rec(global_routing->root);
-  xbt_dynar_free(&global_routing->last_route);
-  xbt_free(global_routing);
-}
 
 static xbt_dynar_t recursive_get_onelink_routes(AS_t rc)
 {
@@ -763,7 +731,6 @@ void routing_model_create(size_t size_of_links, void *loopback)
   global_routing->get_onelink_routes = get_onelink_routes;
   global_routing->get_route_latency = get_route_latency;
   global_routing->get_network_element_type = get_network_element_type;
-  global_routing->finalize = finalize;
   global_routing->loopback = loopback;
   global_routing->size_of_link = size_of_links;
   global_routing->last_route = NULL;
@@ -1273,3 +1240,33 @@ void routing_register_callbacks()
   instr_routing_define_callbacks();
 #endif
 }
+
+/**
+ * \brief Recursive function for finalize
+ *
+ * \param rc the source host name
+ *
+ * This fuction is call by "finalize". It allow to finalize the
+ * AS or routing components. It delete all the structures.
+ */
+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);
+}
+
+/** \brief Frees all memory allocated by the routing module */
+void routing_exit(void) {
+  if (!global_routing)
+    return;
+  finalize_rec(global_routing->root);
+  xbt_dynar_free(&global_routing->last_route);
+  xbt_free(global_routing);
+}
index 82acc84..5d94ad5 100644 (file)
@@ -410,7 +410,6 @@ static void ptask_finalize(void)
   surf_workstation_model = NULL;
   surf_model_exit(surf_network_model);
   surf_network_model = NULL;
-  global_routing->finalize();
 
   ptask_host_count = 0;