From: Martin Quinson Date: Sat, 18 Jul 2015 12:26:59 +0000 (+0200) Subject: New function: sg_hosts_as_dynar X-Git-Tag: v3_12~492 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7feae70bb1a3019393031dcf0bb64daeaa19f4ef New function: sg_hosts_as_dynar This was implemented several times, in each layer --- diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 72d6d99448..a005912916 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -8,6 +8,7 @@ #define SIMGRID_HOST_H_ #include +#include SG_BEGIN_DECL() typedef xbt_dictelm_t sg_host_t; @@ -16,6 +17,7 @@ XBT_PUBLIC(sg_host_t) sg_host_by_name_or_create(const char *name); static XBT_INLINE char *sg_host_get_name(sg_host_t host){ return host->key; } +XBT_PUBLIC(xbt_dynar_t) sg_hosts_as_dynar(void); #ifdef __cplusplus #define DEFINE_EXTERNAL_CLASS(klass) class klass; diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index ceaa015205..27aa5e950a 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -206,18 +206,7 @@ msg_host_t *MSG_get_host_table(void) * \remark The host order in the returned array is generally different from the host creation/declaration order in the XML platform (we use a hash table internally) */ xbt_dynar_t MSG_hosts_as_dynar(void) { - xbt_lib_cursor_t cursor; - char *key; - void **data; - xbt_dynar_t res = xbt_dynar_new(sizeof(msg_host_t),NULL); - - xbt_lib_foreach(host_lib, cursor, key, data) { - if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) { - xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor); - xbt_dynar_push(res, &elm); - } - } - return res; + return sg_hosts_as_dynar(); } /** \ingroup m_host_management diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index bfe57d9717..697d5ee2c6 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -83,26 +83,12 @@ SD_workstation_t SD_workstation_get_by_name(const char *name) * \remark The workstation order in the returned array is generally different from the workstation creation/declaration order in the XML platform (we use a hash table internally). * \see SD_workstation_get_number() */ -const SD_workstation_t *SD_workstation_get_list(void) -{ - - xbt_lib_cursor_t cursor; - char *key; - void **data; - int i; - +const SD_workstation_t *SD_workstation_get_list(void) { xbt_assert(SD_workstation_get_number() > 0, "There is no workstation!"); - if (sd_global->workstation_list == NULL) { /* this is the first time the function is called */ - sd_global->workstation_list = - xbt_new(SD_workstation_t, xbt_lib_length(host_lib)); + if (sd_global->workstation_list == NULL) /* this is the first time the function is called */ + sd_global->workstation_list = xbt_dynar_to_array(sg_hosts_as_dynar()); - i = 0; - xbt_lib_foreach(host_lib, cursor, key, data) { - if(data[SD_HOST_LEVEL]) - sd_global->workstation_list[i++] = xbt_dict_cursor_get_elm(cursor); - } - } return sd_global->workstation_list; } diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 61d2dac72a..7eb97bfe8b 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -7,6 +7,7 @@ #include "xbt/dict.h" #include "simgrid/host.h" #include "surf/surf_routing.h" // SIMIX_HOST_LEVEL and friends FIXME: make private here +#include "surf/surf.h" // routing_get_network_element_type FIXME:killme sg_host_t sg_host_by_name(const char *name){ return xbt_lib_get_elm_or_null(host_lib, name); @@ -20,6 +21,20 @@ sg_host_t sg_host_by_name_or_create(const char *name) { } return res; } +xbt_dynar_t sg_hosts_as_dynar(void) { + xbt_lib_cursor_t cursor; + char *key; + void **data; + xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),NULL); + + xbt_lib_foreach(host_lib, cursor, key, data) { + if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) { + xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor); + xbt_dynar_push(res, &elm); + } + } + return res; +} // ========= Layering madness ==============