From: Martin Quinson Date: Thu, 10 Nov 2011 16:47:24 +0000 (+0100) Subject: factorize the routing_exit functionality, and ensure that no model can forget to... X-Git-Tag: exp_20120216~331 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5e52cdafc655354a1c98193c817fc205d5be353e?hp=b4427e5112f361f205ed20a53d54e15d552f36ff factorize the routing_exit functionality, and ensure that no model can forget to call it --- diff --git a/src/surf/network.c b/src/surf/network.c index e3bd03a974..67213b5aaf 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -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; } diff --git a/src/surf/network_im.c b/src/surf/network_im.c index d3816379e2..b15b936f43 100644 --- a/src/surf/network_im.c +++ b/src/surf/network_im.c @@ -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; diff --git a/src/surf/surf.c b/src/surf/surf.c index f6d9f205be..2f90fa918c 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -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); diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 8739042843..7c2e4ca8d2 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -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); /** diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 07162fa4e0..0f469d5fe9 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -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); +} diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 82acc84256..5d94ad59fb 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -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;